blob: 0f7dc3013b1c558f968a7cdbc4baab3b01663410 (
plain)
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
|
<?php
/**
* Piwik - Open source web analytics
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*
* @category Piwik
* @package Piwik
*/
namespace Piwik;
use Exception;
use Piwik\ScheduledTime;
/**
* ScheduledTask is used by the task scheduler and by plugins to configure runnable tasks.
*
* @package Piwik
* @subpackage ScheduledTask
*
* @api
*/
class ScheduledTask
{
const LOWEST_PRIORITY = 12;
const LOW_PRIORITY = 9;
const NORMAL_PRIORITY = 6;
const HIGH_PRIORITY = 3;
const HIGHEST_PRIORITY = 0;
/**
* Object instance on which the method will be executed by the task scheduler
* @var string
*/
var $objectInstance;
/**
* Class name where the specified method is located
* @var string
*/
var $className;
/**
* Class method to run when task is scheduled
* @var string
*/
var $methodName;
/**
* Parameter to pass to the executed method
* @var string
*/
var $methodParameter;
/**
* The scheduled time policy
* @var ScheduledTime
*/
var $scheduledTime;
/**
* The priority of a task. Affects the order in which this task will be run.
* @var int
*/
var $priority;
function __construct($_objectInstance, $_methodName, $_methodParameter, $_scheduledTime, $_priority = self::NORMAL_PRIORITY)
{
$this->className = $this->getClassNameFromInstance($_objectInstance);
if ($_priority < self::HIGHEST_PRIORITY || $_priority > self::LOWEST_PRIORITY) {
throw new Exception("Invalid priority for ScheduledTask '$this->className.$_methodName': $_priority");
}
$this->objectInstance = $_objectInstance;
$this->methodName = $_methodName;
$this->scheduledTime = $_scheduledTime;
$this->methodParameter = $_methodParameter;
$this->priority = $_priority;
}
protected function getClassNameFromInstance($_objectInstance)
{
if (is_string($_objectInstance)) {
return $_objectInstance;
}
$namespaced = get_class($_objectInstance);
$class = explode('\\', $namespaced);
return end($class);
}
/**
* Return the object instance on which the method should be executed
* @return string
*/
public function getObjectInstance()
{
return $this->objectInstance;
}
/**
* Return class name
* @return string
*/
public function getClassName()
{
return $this->className;
}
/**
* Return method name
* @return string
*/
public function getMethodName()
{
return $this->methodName;
}
/**
* Return method parameter
* @return string
*/
public function getMethodParameter()
{
return $this->methodParameter;
}
/**
* Return scheduled time
* @return ScheduledTime
*/
public function getScheduledTime()
{
return $this->scheduledTime;
}
/**
* Return the rescheduled time in milliseconds
* @return int
*/
public function getRescheduledTime()
{
return $this->getScheduledTime()->getRescheduledTime();
}
/**
* Return the task priority. The priority will be an integer whose value is
* between ScheduledTask::HIGH_PRIORITY and ScheduledTask::LOW_PRIORITY.
*
* @return int
*/
public function getPriority()
{
return $this->priority;
}
public function getName()
{
return self::getTaskName($this->getClassName(), $this->getMethodName(), $this->getMethodParameter());
}
static public function getTaskName($className, $methodName, $methodParameter = null)
{
return $className . '.' . $methodName . ($methodParameter == null ? '' : '_' . $methodParameter);
}
}
|