This repository has been archived by the owner on Apr 4, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
runAgents.php
executable file
·66 lines (55 loc) · 2.05 KB
/
runAgents.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/php
<?php
// vim: fenc=utf-8:ft=php:ai:si:ts=4:sw=4:et:
/**
* Run scheduled agents.
*
* @filesource
* @copyright Copyright (c) 2008-2011 David Smith
* @license http://www.opensource.org/licenses/mit-license.php MIT License
* @package Hashmark
* @subpackage Cron
* @version $Id$
*/
/**
* For getModule().
*/
require_once dirname(__FILE__) . '/../Hashmark.php';
$db = Hashmark::getModule('DbHelper')->openDb('cron');
$core = Hashmark::getModule('Core', '', $db);
$partition = Hashmark::getModule('Partition', '', $db);
$scheduledAgents = $core->getScheduledAgents();
if (empty($scheduledAgents)) {
exit;
}
// Reuse previously loaded agent objects since they have no properties.
$cache = array();
foreach ($scheduledAgents as $scalarAgent) {
if ('Running' == $scalarAgent['status']) {
$core->setScalarAgentStatus($scalarAgent['id'], 'Unscheduled',
'Last run did not finish.');
continue;
}
if (!isset($cache[$scalarAgent['name']])) {
try {
$cache[$scalarAgent['name']] = Hashmark::getModule('Agent',
$scalarAgent['name']);
} catch (Exception $e) {
$error = sprintf('Agent "%s" module missing: %s',
$scalarAgent['name'], $e->getMessage());
$core->setScalarAgentStatus($scalarAgent['id'], 'Unscheduled', $error);
continue;
}
}
if (!$cache[$scalarAgent['name']]) {
$error = "Agent '{$scalarAgent['name']}' was missing";
$core->setScalarAgentStatus($scalarAgent['id'], 'Unscheduled', $error);
continue;
}
$core->setScalarAgentStatus($scalarAgent['id'], 'Running');
$value = $cache[$scalarAgent['name']]->run($scalarAgent);
// run() received $scalarAgent by-ref and can apply indepedent logic
// to set a new status, error message, etc.
$core->setScalarAgentStatus($scalarAgent['id'], $scalarAgent['status'],
$scalarAgent['error'], time());
}