|
1
|
|
|
<?php namespace Comodojo\Extender\Jobs; |
|
2
|
|
|
|
|
3
|
|
|
use \Comodojo\Extender\Components\Niceness; |
|
4
|
|
|
use \Comodojo\Dispatcher\Components\Configuration; |
|
5
|
|
|
use \Psr\Log\LoggerInterface; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* Job runner |
|
9
|
|
|
* |
|
10
|
|
|
* @package Comodojo extender |
|
11
|
|
|
* @author Marco Giovinazzi <[email protected]> |
|
12
|
|
|
* @license GPL-3.0+ |
|
13
|
|
|
* |
|
14
|
|
|
* LICENSE: |
|
15
|
|
|
* |
|
16
|
|
|
* This program is free software: you can redistribute it and/or modify |
|
17
|
|
|
* it under the terms of the GNU Affero General Public License as |
|
18
|
|
|
* published by the Free Software Foundation, either version 3 of the |
|
19
|
|
|
* License, or (at your option) any later version. |
|
20
|
|
|
* |
|
21
|
|
|
* This program is distributed in the hope that it will be useful, |
|
22
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
23
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
24
|
|
|
* GNU Affero General Public License for more details. |
|
25
|
|
|
* |
|
26
|
|
|
* You should have received a copy of the GNU Affero General Public License |
|
27
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
28
|
|
|
*/ |
|
29
|
|
|
|
|
30
|
|
|
class Runner { |
|
31
|
|
|
|
|
32
|
|
|
protected $configuration; |
|
33
|
|
|
|
|
34
|
|
|
protected $logger; |
|
35
|
|
|
|
|
36
|
|
|
protected $niceness; |
|
37
|
|
|
|
|
38
|
|
|
protected $lagger_timeout = 5; |
|
39
|
|
|
|
|
40
|
|
|
public function __construct(Configuration $configuration, LoggerInterface $logger) { |
|
41
|
|
|
|
|
42
|
|
|
// init components |
|
43
|
|
|
$this->configuration = $configuration; |
|
44
|
|
|
|
|
45
|
|
|
$this->logger = $logger; |
|
46
|
|
|
|
|
47
|
|
|
$this->niceness = new Niceness($this->logger); |
|
48
|
|
|
|
|
49
|
|
|
// retrieve parameters |
|
50
|
|
|
|
|
51
|
|
|
$this->lagger_timeout = self::getLaggerTimeout($this->configuration); |
|
52
|
|
|
|
|
53
|
|
|
$this->multithread = $configuration->get('multithread') === true; |
|
|
|
|
|
|
54
|
|
|
|
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
|
|
58
|
|
|
|
|
59
|
|
|
|
|
60
|
|
|
|
|
61
|
|
|
|
|
62
|
|
|
|
|
63
|
|
View Code Duplication |
private static function getLaggerTimeout(Configuration $configuration) { |
|
|
|
|
|
|
64
|
|
|
|
|
65
|
|
|
return filter_var($configuration->get('child-lagger-timeout'), FILTER_VALIDATE_INT, array( |
|
66
|
|
|
'options' => array( |
|
67
|
|
|
'default' => 5, |
|
68
|
|
|
'min_range' => 0 |
|
69
|
|
|
) |
|
70
|
|
|
)); |
|
71
|
|
|
|
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
} |
|
75
|
|
|
|
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: