Attached Files |
Ability-to-specify-Timeout-for-Agents.patch [^] (8,065 bytes) 2011-10-16 13:24
[Show Content]
Index: admin_templates/agents/agent_edit.tpl
===================================================================
--- admin_templates/agents/agent_edit.tpl (revision 14667)
+++ admin_templates/agents/agent_edit.tpl (working copy)
@@ -1,4 +1,4 @@
-<inp2:adm_SetPopupSize width="550" height="400"/>
+<inp2:adm_SetPopupSize width="750" height="600"/>
<inp2:m_include t="incs/header"/>
<inp2:m_RenderElement name="combined_header" section="in-portal:agents" prefix="agent" title_preset="agent_edit"/>
@@ -82,7 +82,8 @@
<inp2:m_RenderElement name="inp_label" prefix="agent" field="LastRunStatus"/>
<inp2:m_RenderElement name="inp_edit_date_time" prefix="agent" field="NextRunOn"/>
<inp2:m_RenderElement name="inp_label" prefix="agent" field="RunTime"/>
-
+ <inp2:m_RenderElement name="inp_edit_box" prefix="agent" field="Timeout"/>
+ <inp2:m_RenderElement name="inp_label" prefix="agent" field="LastTimeoutOn"/>
<inp2:m_RenderElement name="inp_edit_checkboxes" prefix="agent" field="SiteDomainLimitation"/>
<inp2:m_RenderElement name="inp_edit_filler"/>
Index: install/english.lang
===================================================================
--- install/english.lang (revision 14667)
+++ install/english.lang (working copy)
@@ -445,6 +445,7 @@
<PHRASE Label="la_fld_LastName" Module="Core" Type="1" Column="TGFzdCBOYW1l">TGFzdCBOYW1l</PHRASE>
<PHRASE Label="la_fld_LastRunOn" Module="Core" Type="1" Column="TGFzdCBSdW4gT24=">TGFzdCBSdW4gT24=</PHRASE>
<PHRASE Label="la_fld_LastRunStatus" Module="Core" Type="1" Column="TGFzdCBSdW4gU3RhdHVz">TGFzdCBSdW4gU3RhdHVz</PHRASE>
+ <PHRASE Label="la_fld_LastTimeoutOn" Module="Core" Type="1" Hint="RGF0YS90aW1lIHdoZW4gdGhlIGV2ZW50IGhhcyB0aW1lZCBvdXQgbGFzdCB0aW1lLg==" Column="TGFzdCBUaW1lb3V0IE9u">TGFzdCBUaW1lb3V0IE9u</PHRASE>
<PHRASE Label="la_fld_LastUpdatedOn" Module="Core" Type="1" Column="TGFzdCBVcGRhdGVkIE9u">TGFzdCBVcGRhdGVkIE9u</PHRASE>
<PHRASE Label="la_fld_Left" Module="Core" Type="1">TGVmdA==</PHRASE>
<PHRASE Label="la_fld_LineEndings" Module="Core" Type="1">TGluZSBlbmRpbmdz</PHRASE>
@@ -586,6 +587,7 @@
<PHRASE Label="la_fld_ThesaurusType" Module="Core" Type="1" Column="VGhlc2F1cnVzIFR5cGU=">VGhlc2F1cnVzIFR5cGU=</PHRASE>
<PHRASE Label="la_fld_ThousandSep" Module="Core" Type="1">VGhvdXNhbmRzIFNlcGFyYXRvcg==</PHRASE>
<PHRASE Label="la_fld_TimeFormat" Module="Core" Type="1">VGltZSBGb3JtYXQ=</PHRASE>
+ <PHRASE Label="la_fld_Timeout" Module="Core" Type="1" Hint="VGltZW91dCBvZiBldmVudCBzY2hlZHVsZSAoaW4gc2Vjb25kcykuIFNwZWNpZmllZCB2YWx1ZSBtdXN0IGJlIGdyZWF0ZXIgdGhhbiAwIGluIG9yZGVyIGZvciBzeXN0ZW0gdG8gdGltZW91dCBhbHJlYWR5IHJ1bm5pbmcgZXZlbnQgaWYgaXQncyBydW5uaW5nIHRpbWUgZXhjZWVkcyB0aGUgc3BlY2lmaWVkIGhlcmUgdGltZW91dCB2YWx1ZS4=" Column="VGltZW91dA==">VGltZW91dA==</PHRASE>
<PHRASE Label="la_fld_Title" Module="Core" Type="1" Column="VGl0bGU=">VGl0bGU=</PHRASE>
<PHRASE Label="la_fld_To" Module="Core" Type="1">VG8=</PHRASE>
<PHRASE Label="la_fld_ToEmail" Module="Core" Type="1" Column="VG8gRS1tYWls">VG8gRS1tYWls</PHRASE>
Index: install/install_schema.sql
===================================================================
--- install/install_schema.sql (revision 14667)
+++ 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 NOT 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 14667)
+++ install/upgrades.sql (working copy)
@@ -2154,3 +2154,9 @@
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 NOT 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 14667)
+++ kernel/managers/agent_manager.php (working copy)
@@ -79,7 +79,10 @@
if ( !isset($agents) ) {
$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
+ ( LastRunStatus = ' . Agent::LAST_RUN_RUNNING . ' AND Timeout > 0 AND NOW() - LastRunOn > Timeout )
+ )';
$all_agents = $this->Conn->Query($sql);
$agents = Array (
@@ -94,6 +97,7 @@
'LastRunOn' => (int)$agent_data['LastRunOn'],
'NextRunOn' => (int)$agent_data['NextRunOn'],
'Status' => $agent_data['Status'],
+ 'LastRunStatus' => $agent_data['LastRunStatus'],
'SiteDomainLimitation' => $agent_data['SiteDomainLimitation'],
);
}
@@ -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
@@ -213,6 +217,11 @@
'NextRunOn' => $start_time + $agent_data['RunInterval'],
);
+ // remember LastTimeoutOn only for events that are still running and will be reset
+ if ( $agent_data['LastRunStatus'] == Agent::LAST_RUN_RUNNING ) {
+ $fields_hash['LastTimeoutOn'] = $start_time;
+ }
+
$this->Conn->doUpdate(
$fields_hash,
$this->Application->getUnitOption('agent', 'TableName'),
Index: units/agents/agent_eh.php
===================================================================
--- units/agents/agent_eh.php (revision 14667)
+++ units/agents/agent_eh.php (working copy)
@@ -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 14667)
+++ units/agents/agents_config.php (working copy)
@@ -133,6 +133,8 @@
'NextRunOn' => Array ('type' => 'int', 'formatter' => 'kDateFormatter', 'required' => 1, 'default' => '#NOW#'),
'RunTime' => Array ('type' => 'int', 'not_null' => 1, 'default' => 0),
+ 'Timeout' => Array ('type' => 'int', 'not_null' => 1, 'default' => 0),
+ '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 +160,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),
),
),
agent_timeout_feature.patch [^] (10,135 bytes) 2011-10-17 10:49
[Show Content]
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 @@
-<inp2:adm_SetPopupSize width="550" height="400"/>
+<inp2:adm_SetPopupSize width="750" height="600"/>
<inp2:m_include t="incs/header"/>
<inp2:m_RenderElement name="combined_header" section="in-portal:agents" prefix="agent" title_preset="agent_edit"/>
@@ -82,7 +82,12 @@
<inp2:m_RenderElement name="inp_label" prefix="agent" field="LastRunStatus"/>
<inp2:m_RenderElement name="inp_edit_date_time" prefix="agent" field="NextRunOn"/>
<inp2:m_RenderElement name="inp_label" prefix="agent" field="RunTime"/>
+ <inp2:m_RenderElement name="inp_edit_box" prefix="agent" field="Timeout" style="width: 50px"/>
+ <inp2:m_if check="agent_Field" name="LastTimeoutOn" db="db">
+ <inp2:m_RenderElement name="inp_label" prefix="agent" field="LastTimeoutOn"/>
+ </inp2:m_if>
+
<inp2:m_RenderElement name="inp_edit_checkboxes" prefix="agent" field="SiteDomainLimitation"/>
<inp2:m_RenderElement name="inp_edit_filler"/>
Index: install/english.lang
===================================================================
--- install/english.lang (revision 14663)
+++ install/english.lang (working copy)
@@ -445,6 +445,7 @@
<PHRASE Label="la_fld_LastName" Module="Core" Type="1" Column="TGFzdCBOYW1l">TGFzdCBOYW1l</PHRASE>
<PHRASE Label="la_fld_LastRunOn" Module="Core" Type="1" Column="TGFzdCBSdW4gT24=">TGFzdCBSdW4gT24=</PHRASE>
<PHRASE Label="la_fld_LastRunStatus" Module="Core" Type="1" Column="TGFzdCBSdW4gU3RhdHVz">TGFzdCBSdW4gU3RhdHVz</PHRASE>
+ <PHRASE Label="la_fld_LastTimeoutOn" Module="Core" Type="1" Hint="RGF0YS90aW1lIHdoZW4gdGhlIGV2ZW50IGhhcyB0aW1lZCBvdXQgbGFzdCB0aW1lLg==" Column="TGFzdCBUaW1lb3V0IE9u">TGFzdCBUaW1lb3V0IE9u</PHRASE>
<PHRASE Label="la_fld_LastUpdatedOn" Module="Core" Type="1" Column="TGFzdCBVcGRhdGVkIE9u">TGFzdCBVcGRhdGVkIE9u</PHRASE>
<PHRASE Label="la_fld_Left" Module="Core" Type="1">TGVmdA==</PHRASE>
<PHRASE Label="la_fld_LineEndings" Module="Core" Type="1">TGluZSBlbmRpbmdz</PHRASE>
@@ -586,6 +587,7 @@
<PHRASE Label="la_fld_ThesaurusType" Module="Core" Type="1" Column="VGhlc2F1cnVzIFR5cGU=">VGhlc2F1cnVzIFR5cGU=</PHRASE>
<PHRASE Label="la_fld_ThousandSep" Module="Core" Type="1">VGhvdXNhbmRzIFNlcGFyYXRvcg==</PHRASE>
<PHRASE Label="la_fld_TimeFormat" Module="Core" Type="1">VGltZSBGb3JtYXQ=</PHRASE>
+ <PHRASE Label="la_fld_Timeout" Module="Core" Type="1" Hint="VGltZW91dCBvZiBldmVudCBzY2hlZHVsZSAoaW4gc2Vjb25kcykuIFNwZWNpZmllZCB2YWx1ZSBtdXN0IGJlIGdyZWF0ZXIgdGhhbiAwIGluIG9yZGVyIGZvciBzeXN0ZW0gdG8gdGltZW91dCBhbHJlYWR5IHJ1bm5pbmcgZXZlbnQgaWYgaXQncyBydW5uaW5nIHRpbWUgZXhjZWVkcyB0aGUgc3BlY2lmaWVkIGhlcmUgdGltZW91dCB2YWx1ZS4=" Column="VGltZW91dA==">VGltZW91dA==</PHRASE>
<PHRASE Label="la_fld_Title" Module="Core" Type="1" Column="VGl0bGU=">VGl0bGU=</PHRASE>
<PHRASE Label="la_fld_To" Module="Core" Type="1">VG8=</PHRASE>
<PHRASE Label="la_fld_ToEmail" Module="Core" Type="1" Column="VG8gRS1tYWls">VG8gRS1tYWls</PHRASE>
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),
),
),
|