1
|
|
|
<?php namespace Comodojo\Extender\Task; |
2
|
|
|
|
3
|
|
|
use \Comodojo\Foundation\Base\Configuration; |
4
|
|
|
use \Comodojo\Extender\Interfaces\TaskInterface; |
5
|
|
|
use \Comodojo\Foundation\Base\ConfigurationTrait; |
6
|
|
|
use \Comodojo\Foundation\Logging\LoggerTrait; |
7
|
|
|
use \Comodojo\Daemon\Traits\PidTrait; |
8
|
|
|
use \Comodojo\Foundation\Events\EventsTrait; |
9
|
|
|
use \Comodojo\Daemon\Utils\ProcessTools; |
10
|
|
|
use \Psr\Log\LoggerInterface; |
11
|
|
|
use \Comodojo\Foundation\Events\Manager as EventsManager; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* @package Comodojo Extender |
15
|
|
|
* @author Marco Giovinazzi <[email protected]> |
16
|
|
|
* @license MIT |
17
|
|
|
* |
18
|
|
|
* LICENSE: |
19
|
|
|
* |
20
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
21
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
22
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
23
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
24
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
25
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
26
|
|
|
* THE SOFTWARE. |
27
|
|
|
*/ |
28
|
|
|
|
29
|
|
|
abstract class AbstractTask implements TaskInterface { |
30
|
|
|
|
31
|
|
|
use ConfigurationTrait; |
32
|
|
|
use EventsTrait; |
33
|
|
|
use LoggerTrait; |
34
|
|
|
use PidTrait; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @var string |
38
|
|
|
*/ |
39
|
|
|
protected $name; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @var TaskParameters |
43
|
|
|
*/ |
44
|
|
|
protected $parameters; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* {@inheritdoc} |
48
|
|
|
*/ |
49
|
|
|
public function __construct( |
50
|
|
|
Configuration $configuration, |
51
|
|
|
EventsManager $events, |
52
|
|
|
LoggerInterface $logger, |
53
|
|
|
$name, |
54
|
|
|
TaskParameters $parameters |
55
|
|
|
) { |
56
|
|
|
|
57
|
|
|
// Setup task |
58
|
|
|
$this->setConfiguration($configuration); |
59
|
|
|
$this->setEvents($events); |
60
|
|
|
$this->setLogger($logger); |
61
|
|
|
$this->setName($name); |
62
|
|
|
$this->setParameters($parameters); |
63
|
|
|
$this->setPid(ProcessTools::getPid()); |
64
|
|
|
|
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Get niceness of a running process |
69
|
|
|
* |
70
|
|
|
* @param int|null $pid The pid to query, or current process if null |
71
|
|
|
* @return int |
72
|
|
|
*/ |
73
|
|
|
public function getName() { |
74
|
|
|
|
75
|
|
|
return $this->name; |
76
|
|
|
|
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Get niceness of a running process |
81
|
|
|
* |
82
|
|
|
* @param int|null $pid The pid to query, or current process if null |
83
|
|
|
* @return int |
84
|
|
|
*/ |
85
|
|
|
public function getParameters() { |
86
|
|
|
|
87
|
|
|
return $this->parameters; |
88
|
|
|
|
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Get niceness of a running process |
93
|
|
|
* |
94
|
|
|
* @param int|null $pid The pid to query, or current process if null |
95
|
|
|
* @return int |
96
|
|
|
*/ |
97
|
|
|
public function setName($name) { |
98
|
|
|
|
99
|
|
|
$this->name = $name; |
100
|
|
|
|
101
|
|
|
return $this; |
102
|
|
|
|
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* Get niceness of a running process |
107
|
|
|
* |
108
|
|
|
* @param int|null $pid The pid to query, or current process if null |
109
|
|
|
* @return int |
110
|
|
|
*/ |
111
|
|
|
public function setParameters(TaskParameters $parameters) { |
112
|
|
|
|
113
|
|
|
$this->parameters = $parameters; |
114
|
|
|
|
115
|
|
|
return $this; |
116
|
|
|
|
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* The run method; SHOULD be implemented by each task |
121
|
|
|
*/ |
122
|
|
|
abstract public function run(); |
123
|
|
|
|
124
|
|
|
} |
125
|
|
|
|