|
1
|
|
|
<?php namespace Comodojo\Extender\Tasks; |
|
2
|
|
|
|
|
3
|
|
|
use \Comodojo\Dispatcher\Components\Configuration; |
|
4
|
|
|
use \Psr\Log\LoggerInterface; |
|
5
|
|
|
|
|
6
|
|
|
/** |
|
7
|
|
|
* Job runner |
|
8
|
|
|
* |
|
9
|
|
|
* @package Comodojo extender |
|
10
|
|
|
* @author Marco Giovinazzi <[email protected]> |
|
11
|
|
|
* @license GPL-3.0+ |
|
12
|
|
|
* |
|
13
|
|
|
* LICENSE: |
|
14
|
|
|
* |
|
15
|
|
|
* This program is free software: you can redistribute it and/or modify |
|
16
|
|
|
* it under the terms of the GNU Affero General Public License as |
|
17
|
|
|
* published by the Free Software Foundation, either version 3 of the |
|
18
|
|
|
* License, or (at your option) any later version. |
|
19
|
|
|
* |
|
20
|
|
|
* This program is distributed in the hope that it will be useful, |
|
21
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
22
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
23
|
|
|
* GNU Affero General Public License for more details. |
|
24
|
|
|
* |
|
25
|
|
|
* You should have received a copy of the GNU Affero General Public License |
|
26
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
27
|
|
|
*/ |
|
28
|
|
|
|
|
29
|
|
|
class Runner { |
|
30
|
|
|
|
|
31
|
|
|
protected $configuration; |
|
32
|
|
|
|
|
33
|
|
|
protected $logger; |
|
34
|
|
|
|
|
35
|
|
|
public function __construct(Configuration $configuration, LoggerInterface $logger) { |
|
36
|
|
|
|
|
37
|
|
|
// init components |
|
38
|
|
|
$this->configuration = $configuration; |
|
39
|
|
|
|
|
40
|
|
|
$this->logger = $logger; |
|
41
|
|
|
|
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
public function run($id, $task, $class, $timestamp = null, $name = null) { |
|
45
|
|
|
|
|
46
|
|
|
$this->logger->info("Starting task $task ($id) "); |
|
47
|
|
|
|
|
48
|
|
|
try { |
|
49
|
|
|
|
|
50
|
|
|
// create a task instance |
|
51
|
|
|
|
|
52
|
|
|
$thetask = new $class( |
|
53
|
|
|
$this->configuration, |
|
54
|
|
|
$this->logger, |
|
55
|
|
|
$name, |
|
56
|
|
|
$timestamp, |
|
57
|
|
|
$id, |
|
58
|
|
|
$parameters |
|
|
|
|
|
|
59
|
|
|
); |
|
60
|
|
|
|
|
61
|
|
|
// get the task pid (we are in singlethread mode) |
|
62
|
|
|
|
|
63
|
|
|
$pid = $thetask->pid; |
|
64
|
|
|
|
|
65
|
|
|
// run task |
|
66
|
|
|
|
|
67
|
|
|
$result = $thetask->start(); |
|
68
|
|
|
|
|
69
|
|
|
} catch (TaskException $te) { |
|
|
|
|
|
|
70
|
|
|
|
|
71
|
|
|
$this->logger->notice("Job ".$job['name']."(".$job['id'].") ends with error"); |
|
|
|
|
|
|
72
|
|
|
|
|
73
|
|
|
return array($pid, $name, false, $start_timestamp, $te->getEndTimestamp(), $te->getMessage(), $id, $te->getWorklogId()); |
|
|
|
|
|
|
74
|
|
|
|
|
75
|
|
|
} catch (Exception $e) { |
|
|
|
|
|
|
76
|
|
|
|
|
77
|
|
|
$this->logger->notice("Job ".$job['name']."(".$job['id'].") ends with error"); |
|
78
|
|
|
|
|
79
|
|
|
return array($pid, $name, false, $start_timestamp, null, $e->getMessage(), $id, null); |
|
|
|
|
|
|
80
|
|
|
|
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
$this->logger->notice("Job ".$job['name']."(".$job['id'].") ends with ".($result["success"] ? "success" : "failure")); |
|
84
|
|
|
|
|
85
|
|
|
return array($pid, $name, $result["success"], $start_timestamp, $result["timestamp"], $result["result"], $id, $result["worklogid"]); |
|
|
|
|
|
|
86
|
|
|
|
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
} |
This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.