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