|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @package: chapi |
|
4
|
|
|
* |
|
5
|
|
|
* @author: msiebeneicher |
|
6
|
|
|
* @since: 2015-07-29 |
|
7
|
|
|
* |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
namespace Chapi\Entity\Chronos; |
|
11
|
|
|
|
|
12
|
|
|
use Chapi\Entity\Chronos\JobEntity\ContainerEntity; |
|
13
|
|
|
use Chapi\Entity\JobEntityInterface; |
|
14
|
|
|
|
|
15
|
|
|
class ChronosJobEntity implements JobEntityInterface |
|
16
|
|
|
{ |
|
17
|
|
|
public $name = ''; |
|
18
|
|
|
|
|
19
|
|
|
public $command = ''; |
|
20
|
|
|
|
|
21
|
|
|
public $description = ''; |
|
22
|
|
|
|
|
23
|
|
|
public $owner = ''; |
|
24
|
|
|
|
|
25
|
|
|
public $ownerName = ''; |
|
26
|
|
|
|
|
27
|
|
|
public $schedule = ''; // todo: move to separate entity |
|
28
|
|
|
|
|
29
|
|
|
public $scheduleTimeZone = ''; |
|
30
|
|
|
|
|
31
|
|
|
public $parents = []; // todo: move to separate entity |
|
32
|
|
|
|
|
33
|
|
|
public $epsilon = ''; |
|
34
|
|
|
|
|
35
|
|
|
public $executor = ''; |
|
36
|
|
|
|
|
37
|
|
|
public $executorFlags = ''; |
|
38
|
|
|
|
|
39
|
|
|
public $shell = true; |
|
40
|
|
|
|
|
41
|
|
|
public $retries = 0; |
|
42
|
|
|
|
|
43
|
|
|
public $async = false; |
|
44
|
|
|
|
|
45
|
|
|
public $successCount = 0; |
|
46
|
|
|
|
|
47
|
|
|
public $errorCount = 0; |
|
48
|
|
|
|
|
49
|
|
|
public $errorsSinceLastSuccess = 0; |
|
50
|
|
|
|
|
51
|
|
|
public $lastSuccess = ''; |
|
52
|
|
|
|
|
53
|
|
|
public $lastError = ''; |
|
54
|
|
|
|
|
55
|
|
|
public $cpus = 0.1; |
|
56
|
|
|
|
|
57
|
|
|
public $disk = 24; |
|
58
|
|
|
|
|
59
|
|
|
public $mem = 32; |
|
60
|
|
|
|
|
61
|
|
|
public $disabled = false; |
|
62
|
|
|
|
|
63
|
|
|
public $softError = false; |
|
64
|
|
|
|
|
65
|
|
|
public $dataProcessingJobType = false; |
|
66
|
|
|
|
|
67
|
|
|
public $uris = []; |
|
68
|
|
|
|
|
69
|
|
|
public $environmentVariables = []; |
|
70
|
|
|
|
|
71
|
|
|
public $arguments = []; |
|
72
|
|
|
|
|
73
|
|
|
public $highPriority = false; |
|
74
|
|
|
|
|
75
|
|
|
public $runAsUser = 'root'; |
|
76
|
|
|
|
|
77
|
|
|
public $constraints = []; |
|
78
|
|
|
|
|
79
|
|
|
/** @var ContainerEntity */ |
|
80
|
|
|
public $container = null; |
|
81
|
|
|
|
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* @param array|object $jobData |
|
85
|
|
|
* @throws \InvalidArgumentException |
|
86
|
|
|
*/ |
|
87
|
116 |
|
public function __construct($jobData = []) |
|
88
|
|
|
{ |
|
89
|
116 |
|
if (is_array($jobData) || is_object($jobData)) { |
|
90
|
115 |
|
foreach ($jobData as $key => $value) { |
|
91
|
17 |
|
if (property_exists($this, $key)) { |
|
92
|
17 |
|
if ($key == 'container') { |
|
93
|
2 |
|
$this->{$key} = new ContainerEntity($value); |
|
94
|
|
|
} else { |
|
95
|
115 |
|
$this->{$key} = $value; |
|
96
|
|
|
} |
|
97
|
|
|
} |
|
98
|
|
|
} |
|
99
|
|
|
} else { |
|
100
|
1 |
|
throw new \InvalidArgumentException(sprintf('Argument 1 passed to "%s" must be an array or object', __METHOD__)); |
|
101
|
|
|
} |
|
102
|
114 |
|
} |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* return entity as one-dimensional array |
|
106
|
|
|
* |
|
107
|
|
|
* @return mixed[] |
|
108
|
|
|
*/ |
|
109
|
8 |
|
public function getSimpleArrayCopy() |
|
110
|
|
|
{ |
|
111
|
8 |
|
$return = []; |
|
112
|
|
|
|
|
113
|
8 |
|
foreach ($this as $property => $value) { |
|
114
|
8 |
|
$return[$property] = (is_array($value) || is_object($value)) ? json_encode($value) : $value; |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
8 |
|
return $return; |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
/** |
|
121
|
|
|
* @return bool |
|
122
|
|
|
*/ |
|
123
|
18 |
|
public function isSchedulingJob() |
|
124
|
|
|
{ |
|
125
|
18 |
|
return (!empty($this->schedule) && empty($this->parents)); |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
/** |
|
129
|
|
|
* @return bool |
|
130
|
|
|
*/ |
|
131
|
7 |
|
public function isDependencyJob() |
|
132
|
|
|
{ |
|
133
|
7 |
|
return (empty($this->schedule) && !empty($this->parents)); |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
/** |
|
137
|
|
|
* @return array |
|
138
|
|
|
*/ |
|
139
|
11 |
|
public function jsonSerialize() |
|
140
|
|
|
{ |
|
141
|
11 |
|
$return = (array) $this; |
|
142
|
11 |
|
if (!empty($this->schedule)) { |
|
143
|
10 |
|
unset($return['parents']); |
|
144
|
|
|
} else { |
|
145
|
1 |
|
unset($return['schedule']); |
|
146
|
1 |
|
unset($return['scheduleTimeZone']); |
|
147
|
|
|
} |
|
148
|
|
|
|
|
149
|
11 |
|
if (empty($this->container)) { |
|
150
|
11 |
|
unset($return['container']); |
|
151
|
|
|
} |
|
152
|
|
|
|
|
153
|
11 |
|
unset($return['successCount']); |
|
154
|
11 |
|
unset($return['errorCount']); |
|
155
|
11 |
|
unset($return['errorsSinceLastSuccess']); |
|
156
|
11 |
|
unset($return['lastSuccess']); |
|
157
|
11 |
|
unset($return['lastError']); |
|
158
|
|
|
|
|
159
|
11 |
|
return $return; |
|
160
|
|
|
} |
|
161
|
|
|
|
|
162
|
|
|
/** |
|
163
|
|
|
* @return \ArrayIterator |
|
164
|
|
|
*/ |
|
165
|
9 |
|
public function getIterator() |
|
166
|
|
|
{ |
|
167
|
9 |
|
return new \ArrayIterator($this); |
|
168
|
|
|
} |
|
169
|
|
|
|
|
170
|
|
|
/** |
|
171
|
|
|
* @return string |
|
172
|
|
|
*/ |
|
173
|
5 |
|
public function getEntityType() |
|
174
|
|
|
{ |
|
175
|
5 |
|
return JobEntityInterface::CHRONOS_TYPE; |
|
176
|
|
|
} |
|
177
|
|
|
|
|
178
|
|
|
/** |
|
179
|
|
|
* @return string |
|
180
|
|
|
*/ |
|
181
|
41 |
|
public function getKey() |
|
182
|
|
|
{ |
|
183
|
41 |
|
return $this->name; |
|
184
|
|
|
} |
|
185
|
|
|
} |
|
186
|
|
|
|