fmsystem-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Fmsystem-commits] [8624] Api: allow cron-jobs to loop over broken queri


From: Sigurd Nes
Subject: [Fmsystem-commits] [8624] Api: allow cron-jobs to loop over broken queries
Date: Fri, 20 Jan 2012 13:38:17 +0000

Revision: 8624
          http://svn.sv.gnu.org/viewvc/?view=rev&root=fmsystem&revision=8624
Author:   sigurdne
Date:     2012-01-20 13:38:16 +0000 (Fri, 20 Jan 2012)
Log Message:
-----------
Api: allow cron-jobs to loop over broken queries

Modified Paths:
--------------
    trunk/phpgwapi/cron/asyncservices.php
    trunk/phpgwapi/inc/class.asyncservice.inc.php
    trunk/phpgwapi/inc/class.db_pdo.inc.php

Modified: trunk/phpgwapi/cron/asyncservices.php
===================================================================
--- trunk/phpgwapi/cron/asyncservices.php       2012-01-20 13:33:44 UTC (rev 
8623)
+++ trunk/phpgwapi/cron/asyncservices.php       2012-01-20 13:38:16 UTC (rev 
8624)
@@ -56,7 +56,9 @@
        */
        include(PHPGW_API_INC.'/functions.inc.php');
        
+       echo 'Start cron: ' . date('Y/m/d H:i:s ') . "\n";
        $num = ExecMethod('phpgwapi.asyncservice.check_run','crontab');
+       echo 'End cron: ' . date('Y/m/d H:i:s ') . "\n";
        // if the following comment got removed, you will get an email from 
cron for every check performed
        //echo date('Y/m/d H:i:s ').$_GET['domain'].': '.($num ? "$num job(s) 
executed" : 'Nothing to execute')."\n";
 

Modified: trunk/phpgwapi/inc/class.asyncservice.inc.php
===================================================================
--- trunk/phpgwapi/inc/class.asyncservice.inc.php       2012-01-20 13:33:44 UTC 
(rev 8623)
+++ trunk/phpgwapi/inc/class.asyncservice.inc.php       2012-01-20 13:38:16 UTC 
(rev 8624)
@@ -34,6 +34,7 @@
                var $db;
                var $db_table = 'phpgw_async';
                var $debug = false;
+               protected $Exception_On_Error = false;
 
                /**
                * Constructor
@@ -43,6 +44,7 @@
                        $this->db =& $GLOBALS['phpgw']->db;
                        $this->cronline = PHPGW_SERVER_ROOT . 
'/phpgwapi/cron/asyncservices.php '.$GLOBALS['phpgw_info']['user']['domain'];
                        $this->only_fallback = substr(php_uname(), 0, 7) == 
"Windows";  // atm cron-jobs dont work on win
+                       $this->Exception_On_Error =     
$GLOBALS['phpgw']->db->Exception_On_Error; // continue on dberror
                }
 
                /**
@@ -383,6 +385,7 @@
                function check_run($run_by='')
                {
                        flush();
+                       $error = false;
 
                        if (!$this->last_check_run(True,False,$run_by))
                        {
@@ -420,29 +423,56 @@
                                        list($app) = 
explode('.',$job['method']);
                                        
$GLOBALS['phpgw']->translation->add_app($app);
 
+                                       
$GLOBALS['phpgw']->db->Exception_On_Error = true;
+
                                        if($job['next'] <= time())
                                        {
-                                               
ExecMethod($job['method'],$job['data']);
-                                       }
+                                               try
+                                               {
+                                                       echo 
"{$job['method']}\n";
+                                                       
ExecMethod($job['method'],$job['data']);
+                                               }
+                                               catch (Exception $e)
+                                               {
+                                                       if($e)
+                                                       {
+                                                               
$GLOBALS['phpgw']->log->error(array(
+                                                                       'text'  
=> 'asyncservice::check_run() : error when trying to execute %1. Error: %2',
+                                                                       'p1'    
=> $job['method'],
+                                                                       'p2'    
=> $e->getMessage(),
+                                                                       'line'  
=> __LINE__,
+                                                                       'file'  
=> __FILE__
+                                                               ));
 
-                                       if ($job['next'] = 
$this->next_run($job['times']))
-                                       {
-                                               $updated_jobs = 
$this->read($id);
-                                               if (isset($updated_jobs[$id]) 
&& isset($updated_jobs[$id]['data']))
-                                               { // update async data field, 
it could be changed during ExecMethod()
-                                                       $job['data'] = 
$updated_jobs[$id]['data'];
+                                                               // Do not throw 
further - it will stop the loop
+                                                               // in case of a 
manual run
+                                                               echo 
$e->getMessage() . "\n";
+                                                               continue;
+                                                       }
                                                }
-                                               // TK 20.11.06 write job to get 
'next' and alarm updated
-                                               $job['data']['time'] = 
$job['next'];
-                                               $this->write($job);
                                        }
-                                       else    // no further runs
-                                       {
-                                               if($job['next'] <= time())
+
+                                       
$GLOBALS['phpgw']->db->Exception_On_Error = $this->Exception_On_Error;
+
+                                               if ($job['next'] = 
$this->next_run($job['times']))
                                                {
-                                                       
$this->delete($job['id']);
+                                                       $updated_jobs = 
$this->read($id);
+                                                       if 
(isset($updated_jobs[$id]) && isset($updated_jobs[$id]['data']))
+                                                       { // update async data 
field, it could be changed during ExecMethod()
+                                                               $job['data'] = 
$updated_jobs[$id]['data'];
+                                                       }
+                                                       // TK 20.11.06 write 
job to get 'next' and alarm updated
+                                                       $job['data']['time'] = 
$job['next'];
+                                                       $this->write($job);
                                                }
-                                       }
+                                               else    // no further runs
+                                               {
+                                                       if($job['next'] <= 
time())
+                                                       {
+                                                               
$this->delete($job['id']);
+                                                       }
+                                               }
+
                                }
                        }
                        $this->last_check_run(True,True,$run_by);       // 
release semaphore

Modified: trunk/phpgwapi/inc/class.db_pdo.inc.php
===================================================================
--- trunk/phpgwapi/inc/class.db_pdo.inc.php     2012-01-20 13:33:44 UTC (rev 
8623)
+++ trunk/phpgwapi/inc/class.db_pdo.inc.php     2012-01-20 13:38:16 UTC (rev 
8624)
@@ -365,7 +365,7 @@
 
                        catch(PDOException $e)
                        {
-                               if ( $e && $this->Halt_On_Error == 'yes' )
+                               if ( $e && !$this->Exception_On_Error && 
$this->Halt_On_Error == 'yes' )
                                {
                                        $this->transaction_abort();
 
@@ -379,10 +379,15 @@
                                        }
                                        exit;
                                }
-                               else if($this->Exception_On_Error)
+                               else if($this->Exception_On_Error && 
$this->Halt_On_Error == 'yes')
                                {
+                                       $this->transaction_abort();
                                        throw $e;
                                }
+                               else if($this->Exception_On_Error && 
$this->Halt_On_Error != 'yes')
+                               {
+                                       throw $e;
+                               }
                        }
                        $this->delayPointer = true;
                        return true;
@@ -451,7 +456,7 @@
 
                        catch(PDOException $e)
                        {
-                               if ( $e && $this->Halt_On_Error == 'yes' )
+                               if ( $e && !$this->Exception_On_Error && 
$this->Halt_On_Error == 'yes' )
                                {
                                        $this->transaction_abort();
 
@@ -465,10 +470,15 @@
                                        }
                                        exit;
                                }
-                               else if($this->Exception_On_Error)
+                               else if($this->Exception_On_Error && 
$this->Halt_On_Error == 'yes')
                                {
+                                       $this->transaction_abort();
                                        throw $e;
                                }
+                               else if($this->Exception_On_Error && 
$this->Halt_On_Error != 'yes')
+                               {
+                                       throw $e;
+                               }
                        }
 
                        $this->delayPointer = true;




reply via email to

[Prev in Thread] Current Thread [Next in Thread]