Index: branches/5.2.x/core/admin_templates/agents/agent_edit.tpl =================================================================== diff -u -N -r14605 -r14670 --- branches/5.2.x/core/admin_templates/agents/agent_edit.tpl (.../agent_edit.tpl) (revision 14605) +++ branches/5.2.x/core/admin_templates/agents/agent_edit.tpl (.../agent_edit.tpl) (revision 14670) @@ -1,4 +1,4 @@ - + @@ -82,7 +82,12 @@ + + + + + Index: branches/5.2.x/core/kernel/managers/agent_manager.php =================================================================== diff -u -N -r14605 -r14670 --- branches/5.2.x/core/kernel/managers/agent_manager.php (.../agent_manager.php) (revision 14605) +++ branches/5.2.x/core/kernel/managers/agent_manager.php (.../agent_manager.php) (revision 14670) @@ -1,6 +1,6 @@ 0 AND ' . adodb_mktime() . ' - LastRunOn > Timeout'; + $sql = 'SELECT * FROM ' . $this->Application->getUnitOption('agent', 'TableName') . ' - WHERE Status = ' . STATUS_ACTIVE . ' AND LastRunStatus <> ' . Agent::LAST_RUN_RUNNING; + WHERE (Status = ' . STATUS_ACTIVE . ') AND ((LastRunStatus != ' . Agent::LAST_RUN_RUNNING . ') OR (' . $timeout_clause . '))'; $all_agents = $this->Conn->Query($sql); $agents = Array ( @@ -94,6 +96,7 @@ 'LastRunOn' => (int)$agent_data['LastRunOn'], 'NextRunOn' => (int)$agent_data['NextRunOn'], 'Status' => $agent_data['Status'], + 'LastRunStatus' => $agent_data['LastRunStatus'], 'SiteDomainLimitation' => $agent_data['SiteDomainLimitation'], ); } @@ -121,10 +124,11 @@ /** * Add new agent * - * @param string $short_name name to be used to store last maintenace run info + * @param string $short_name name to be used to store last maintenance run info * @param string $event_name * @param int $run_interval run interval in seconds * @param int $type before or after agent + * @param int $status * @access public */ public function add($short_name, $event_name, $run_interval, $type = reBEFORE, $status = STATUS_ACTIVE) @@ -137,7 +141,7 @@ } /** - * Run registred agents with specified event type + * Run registered agents with specified event type * * @param int $event_type * @param bool $from_cron @@ -175,6 +179,11 @@ } } + // remember LastTimeoutOn only for events that are still running and will be reset + if ( $event_data['LastRunStatus'] == Agent::LAST_RUN_RUNNING ) { + $this->updateAgent($short_name, Array ('LastTimeoutOn' => adodb_mktime())); + } + $next_run = $event_data['NextRunOn']; if ($next_run && ($next_run > adodb_mktime())) { @@ -213,11 +222,7 @@ 'NextRunOn' => $start_time + $agent_data['RunInterval'], ); - $this->Conn->doUpdate( - $fields_hash, - $this->Application->getUnitOption('agent', 'TableName'), - 'AgentName = ' . $this->Conn->qstr($agent_data['AgentName']) - ); + $this->updateAgent($agent_data['AgentName'], $fields_hash); $event->redirect = false; $this->Application->HandleEvent($event); @@ -237,12 +242,25 @@ 'LastRunStatus' => $event->status == kEvent::erSUCCESS ? Agent::LAST_RUN_SUCCEDED : Agent::LAST_RUN_FAILED, ); + $this->updateAgent($agent_data['AgentName'], $fields_hash); + + return true; + } + + /** + * Updates agent record with latest changes about it's invocation progress + * + * @param string $agent_name + * @param Array $fields_hash + * @return void + * @access protected + */ + protected function updateAgent($agent_name, $fields_hash) + { $this->Conn->doUpdate( $fields_hash, $this->Application->getUnitOption('agent', 'TableName'), - 'AgentName = ' . $this->Conn->qstr($agent_data['AgentName']) + 'AgentName = ' . $this->Conn->qstr($agent_name) ); - - return true; } } \ No newline at end of file Index: branches/5.2.x/core/install/install_schema.sql =================================================================== diff -u -N -r14662 -r14670 --- branches/5.2.x/core/install/install_schema.sql (.../install_schema.sql) (revision 14662) +++ branches/5.2.x/core/install/install_schema.sql (.../install_schema.sql) (revision 14670) @@ -673,6 +673,8 @@ LastRunStatus tinyint(3) unsigned NOT NULL default '1', NextRunOn int(11) default NULL, RunTime int(10) unsigned NOT NULL default '0', + Timeout int(10) UNSIGNED NULL, + LastTimeoutOn int(10) unsigned default NULL, SiteDomainLimitation varchar(255) NOT NULL, PRIMARY KEY (AgentId), KEY Status (Status), @@ -683,6 +685,7 @@ KEY LastRunStatus (LastRunStatus), KEY RunTime (RunTime), KEY NextRunOn (NextRunOn), + KEY Timeout (Timeout), KEY SiteDomainLimitation (SiteDomainLimitation) ); Index: branches/5.2.x/core/units/agents/agent_eh.php =================================================================== diff -u -N -r14628 -r14670 --- branches/5.2.x/core/units/agents/agent_eh.php (.../agent_eh.php) (revision 14628) +++ branches/5.2.x/core/units/agents/agent_eh.php (.../agent_eh.php) (revision 14670) @@ -1,6 +1,6 @@ Array ('type' => 'int', 'formatter' => 'kDateFormatter', 'required' => 1, 'default' => '#NOW#'), 'RunTime' => Array ('type' => 'int', 'not_null' => 1, 'default' => 0), + 'Timeout' => Array ( + 'type' => 'int', + 'min_value_inc' => 1, + 'not_null' => 1, 'default' => NULL + ), + 'LastTimeoutOn' => Array ('type' => 'int', 'formatter' => 'kDateFormatter', 'default' => NULL), 'SiteDomainLimitation' => Array ( 'type' => 'string', 'max_len' => 255, 'formatter' => 'kOptionsFormatter', 'options_sql' => 'SELECT %s FROM ' . TABLE_PREFIX . 'SiteDomains ORDER BY DomainName ASC', 'option_key_field' => 'DomainId', 'option_title_field' => 'DomainName', 'multiple' => 1, @@ -158,6 +164,8 @@ 'LastRunStatus' => Array ('filter_block' => 'grid_options_filter', 'width' => 120, ), 'NextRunOn' => Array ('filter_block' => 'grid_date_range_filter', 'width' => 145, ), 'Status' => Array ('filter_block' => 'grid_options_filter', 'width' => 65, ), + 'Timeout' => Array ('filter_block' => 'grid_range_filter', 'width' => 85, ), + 'LastTimeoutOn' => Array ('filter_block' => 'grid_date_range_filter', 'width' => 145, ), 'SiteDomainLimitation' => Array ('data_block' => 'grid_picker_td', 'filter_block' => 'grid_multioptions_filter', 'separator' => ', ', 'width' => 145), ), ), Index: branches/5.2.x/core/install/english.lang =================================================================== diff -u -N -r14663 -r14670 --- branches/5.2.x/core/install/english.lang (.../english.lang) (revision 14663) +++ branches/5.2.x/core/install/english.lang (.../english.lang) (revision 14670) @@ -445,6 +445,7 @@ TGFzdCBOYW1l TGFzdCBSdW4gT24= TGFzdCBSdW4gU3RhdHVz + TGFzdCBUaW1lb3V0IE9u TGFzdCBVcGRhdGVkIE9u TGVmdA== TGluZSBlbmRpbmdz @@ -586,6 +587,7 @@ VGhlc2F1cnVzIFR5cGU= VGhvdXNhbmRzIFNlcGFyYXRvcg== VGltZSBGb3JtYXQ= + VGltZW91dA== VGl0bGU= VG8= VG8gRS1tYWls