rules_scheduler.handler.inc
2.57 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<?php
/**
* Default scheduled task handler.
*/
class RulesSchedulerDefaultTaskHandler implements RulesSchedulerTaskHandlerInterface {
/**
* The task array.
*
* @var array
*/
protected $task;
/**
* Constructs a repetitive task handler object.
*/
public function __construct(array $task) {
$this->task = $task;
}
/**
* Implements RulesSchedulerTaskHandlerInterface::runTask().
*/
public function runTask() {
if ($component = rules_get_cache('comp_' . $this->task['config'])) {
$replacements = array('%label' => $component->label(), '%plugin' => $component->plugin());
$replacements['%identifier'] = $this->task['identifier'] ? $this->task['identifier'] : t('without identifier');
rules_log('Scheduled evaluation of %plugin %label, task %identifier.', $replacements, RulesLog::INFO, $component, TRUE);
$state = unserialize($this->task['data']);
$state->restoreBlocks();
// Block the config to prevent any future recursion.
$state->block($component);
// Finally evaluate the component with the given state.
$component->evaluate($state);
$state->unblock($component);
rules_log('Finished evaluation of %plugin %label, task %identifier.', $replacements, RulesLog::INFO, $component, FALSE);
$state->cleanUp();
}
}
/**
* Implements RulesSchedulerTaskHandlerInterface::afterTaskQueued().
*/
public function afterTaskQueued() {
// Delete the task from the task list.
db_delete('rules_scheduler')
->condition('tid', $this->task['tid'])
->execute();
}
/**
* Implements RulesSchedulerTaskHandlerInterface::getTask().
*/
public function getTask() {
return $this->task;
}
}
/**
* Interface for scheduled task handlers.
*
* Task handlers control the behavior of a task when it's queued or executed.
* Unless specified otherwise, the RulesSchedulerDefaultTaskHandler task handler
* is used.
*
* @see rules_scheduler_run_task()
* @see rules_scheduler_cron()
* @see RulesSchedulerDefaultTaskHandler
*/
interface RulesSchedulerTaskHandlerInterface {
/**
* Processes a queue item.
*
* @throws RulesEvaluationException
* If there are any problems executing the task.
*
* @see rules_scheduler_run_task()
*/
public function runTask();
/**
* Processes a task after it has been queued.
*
* @see rules_scheduler_cron()
*/
public function afterTaskQueued();
/**
* Returns the task associated with the task handler.
*
* @return array
* The task (queue item) array.
*/
public function getTask();
}