Index: admin_templates/agents/agent_edit.tpl =================================================================== --- admin_templates/agents/agent_edit.tpl (revision 14653) +++ admin_templates/agents/agent_edit.tpl (working copy) @@ -1,4 +1,4 @@ - + @@ -82,7 +82,12 @@ + + + + + Index: install/english.lang =================================================================== --- install/english.lang (revision 14663) +++ install/english.lang (working copy) @@ -445,6 +445,7 @@ TGFzdCBOYW1l TGFzdCBSdW4gT24= TGFzdCBSdW4gU3RhdHVz + TGFzdCBUaW1lb3V0IE9u TGFzdCBVcGRhdGVkIE9u TGVmdA== TGluZSBlbmRpbmdz @@ -586,6 +587,7 @@ VGhlc2F1cnVzIFR5cGU= VGhvdXNhbmRzIFNlcGFyYXRvcg== VGltZSBGb3JtYXQ= + VGltZW91dA== VGl0bGU= VG8= VG8gRS1tYWls Index: install/install_schema.sql =================================================================== --- install/install_schema.sql (revision 14662) +++ install/install_schema.sql (working copy) @@ -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: install/upgrades.sql =================================================================== --- install/upgrades.sql (revision 14662) +++ install/upgrades.sql (working copy) @@ -2154,3 +2154,8 @@ INSERT INTO Permissions VALUES (DEFAULT, 'in-portal:permission_types.add', 11, 1, 1, 0); INSERT INTO Permissions VALUES (DEFAULT, 'in-portal:permission_types.edit', 11, 1, 1, 0); INSERT INTO Permissions VALUES (DEFAULT, 'in-portal:permission_types.delete', 11, 1, 1, 0); + +ALTER TABLE Agents + ADD Timeout INT(10) UNSIGNED NULL AFTER RunTime, + ADD LastTimeoutOn int(10) unsigned default NULL AFTER Timeout, + ADD INDEX (Timeout); \ No newline at end of file Index: kernel/managers/agent_manager.php =================================================================== --- kernel/managers/agent_manager.php (revision 14653) +++ kernel/managers/agent_manager.php (working copy) @@ -77,9 +77,11 @@ } if ( !isset($agents) ) { + $timeout_clause = 'LastRunStatus = ' . Agent::LAST_RUN_RUNNING . ' AND Timeout > 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: units/agents/agent_eh.php =================================================================== --- units/agents/agent_eh.php (revision 14653) +++ units/agents/agent_eh.php (working copy) @@ -17,7 +17,7 @@ class AgentEventHandler extends kDBEventHandler { /** - * Allows to override standart permission mapping + * Allows to override standard permission mapping * */ function mapPermissions() @@ -121,7 +121,7 @@ } /** - * Cancels agents, that are currenty running + * Cancels agents, that are currently running * * @param kEvent $event */ Index: units/agents/agents_config.php =================================================================== --- units/agents/agents_config.php (revision 14653) +++ units/agents/agents_config.php (working copy) @@ -133,6 +133,12 @@ 'NextRunOn' => 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), ), ),