1 | <?php namespace Comodojo\Extender\Task; |
||
40 | abstract class Task { |
||
41 | |||
42 | // Things a task may modify |
||
43 | |||
44 | /** |
||
45 | * The job name |
||
46 | * |
||
47 | * @var string |
||
48 | */ |
||
49 | private $name = 'EXTENDERTASK'; |
||
50 | |||
51 | /** |
||
52 | * Job class (the one that extend cron_job). |
||
53 | * |
||
54 | * @var string |
||
55 | */ |
||
56 | private $class = null; |
||
57 | |||
58 | /** |
||
59 | * Logger, injected by extender |
||
60 | * |
||
61 | * @var \Monolog\Logger |
||
62 | */ |
||
63 | protected $logger = null; |
||
64 | |||
65 | /** |
||
66 | * Start timestamp |
||
67 | * |
||
68 | * @var int |
||
69 | */ |
||
70 | private $start_timestamp = null; |
||
71 | |||
72 | /** |
||
73 | * End timestamp |
||
74 | * |
||
75 | * @var int |
||
76 | */ |
||
77 | private $end_timestamp = null; |
||
78 | |||
79 | /** |
||
80 | * Current process PID |
||
81 | */ |
||
82 | private $pid = null; |
||
83 | |||
84 | /** |
||
85 | * Id of the job that launched this tasks |
||
86 | */ |
||
87 | private $jobid = null; |
||
88 | |||
89 | /** |
||
90 | * The job result (if any) |
||
91 | */ |
||
92 | private $job_result = null; |
||
|
|||
93 | |||
94 | /** |
||
95 | * The job end state |
||
96 | */ |
||
97 | private $job_success = false; |
||
98 | |||
99 | /** |
||
100 | * Worklog ID |
||
101 | */ |
||
102 | private $worklog_id = null; |
||
103 | |||
104 | /** |
||
105 | * Parameters that extender may provide |
||
106 | */ |
||
107 | private $parameters = array(); |
||
108 | |||
109 | /** |
||
110 | * Database handler |
||
111 | */ |
||
112 | private $dbh = array(); |
||
113 | |||
114 | /** |
||
115 | * Task constructor. |
||
116 | * |
||
117 | * @param array $parameters Array of parameters (if any) |
||
118 | * @param \Monolog\Logger $logger |
||
119 | * @param int $pid Task PID (if any) |
||
120 | * @param string $name Task Name |
||
121 | * @param int $timestamp Start timestamp (if null will be retrieved directly) |
||
122 | * @param bool $multithread Multithread switch |
||
123 | * |
||
124 | * @return Object $this |
||
125 | */ |
||
126 | final public function __construct($parameters, Logger $logger, |
||
185 | |||
186 | /** |
||
187 | * Class destructor, just to unset database handler |
||
188 | * |
||
189 | */ |
||
190 | final public function __destruct() { |
||
195 | |||
196 | /** |
||
197 | * Get all provided parameters in array |
||
198 | * |
||
199 | * @return Array |
||
200 | */ |
||
201 | final public function getParameters() { |
||
206 | |||
207 | /** |
||
208 | * Get a provided parameter's value |
||
209 | * |
||
210 | * @return mixed parameter value if provided or null otherwise |
||
211 | */ |
||
212 | final public function getParameter($parameter) { |
||
219 | |||
220 | /** |
||
221 | * Return PID from system (null if no multi-thread active) |
||
222 | * |
||
223 | * @return int |
||
224 | */ |
||
225 | final public function getPid() { |
||
230 | |||
231 | /** |
||
232 | * Start task! |
||
233 | * |
||
234 | * @return array |
||
235 | */ |
||
236 | final public function start() { |
||
252 | |||
253 | /** |
||
254 | * Execute task. |
||
255 | * |
||
256 | * This method provides to: |
||
257 | * - setup worklog |
||
258 | * - invoke method "run", that should be defined in task implementation |
||
259 | */ |
||
260 | private function execTask() { |
||
299 | |||
300 | /** |
||
301 | * The run method; SHOULD be implemented by each task |
||
302 | */ |
||
303 | abstract public function run(); |
||
304 | |||
305 | /** |
||
306 | * Create the worklog for current job |
||
307 | */ |
||
308 | protected function createWorklog() { |
||
329 | |||
330 | /** |
||
331 | * Close worklog for current job |
||
332 | */ |
||
333 | protected function closeWorklog($success) { |
||
352 | |||
353 | } |
||
354 |
This check marks private properties in classes that are never used. Those properties can be removed.