Completed
Push — 2.0 ( 76e968...4129d9 )
by Marco
13:01
created

Request::getTask()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php namespace Comodojo\Extender\Task;
2
3
use \Comodojo\Foundation\Utils\UniqueId;
4
use \Comodojo\Extender\Utils\Validator;
5
6
/**
7
* @package     Comodojo Extender
8
* @author      Marco Giovinazzi <[email protected]>
9
* @license     MIT
10
*
11
* LICENSE:
12
*
13
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
* THE SOFTWARE.
20
 */
21
22
23
class Request {
24
25
    /**
26
     * @var string
27
     */
28
    protected $name;
29
30
    /**
31
     * @var string
32
     */
33
    protected $task;
34
35
    /**
36
     * @var int
37
     */
38
    protected $uid;
39
40
    /**
41
     * @var int
42
     */
43
    protected $parent_uid;
44
45
    /**
46
     * @var int
47
     */
48
    protected $jid;
49
50
    /**
51
     * @var int
52
     */
53
    protected $niceness = 0;
54
55
    /**
56
     * @var int
57
     */
58
    protected $maxtime = 600;
59
60
    /**
61
     * @var int
62
     */
63
    protected $start_timestamp;
64
65
    /**
66
     * @var int
67
     */
68
    protected $pid;
69
70
    /**
71
     * @var Request
72
     */
73
    protected $done;
74
75
    /**
76
     * @var Request
77
     */
78
    protected $fail;
79
80
    /**
81
     * @var Request
82
     */
83
    protected $pipe;
84
85
    /**
86
     * @var TaskParameters
87
     */
88
    protected $parameters = null;
89
90
    /**
91
     * Class constructor
92
     *
93
     * @param string $name
94
     * @param string $task
95
     * @param TaskParameters $parameters
96
     */
97
    public function __construct($name, $task, TaskParameters $parameters = null) {
98
99
        $this->uid = UniqueId::generate();
100
101
        $this->setName($name);
102
        $this->setTask($task);
103
        $this->setParameters($parameters);
104
105
    }
106
107
    /**
108
     * Get request name
109
     *
110
     * @return string
111
     */
112
    public function getName() {
113
114
        return $this->name;
115
116
    }
117
118
    public function setName($name) {
119
120
        $this->name = $name;
121
122
        return $this;
123
124
    }
125
126
    /**
127
     * Get request associated task
128
     *
129
     * @return string
130
     */
131
    public function getTask() {
132
133
        return $this->task;
134
135
    }
136
137
    public function setTask($task) {
138
139
        $this->task = $task;
140
141
        return $this;
142
143
    }
144
145
    /**
146
     * Get current unique id
147
     *
148
     * @return int
149
     */
150
    public function getUid() {
151
152
        return $this->uid;
153
154
    }
155
156
    public function setUid($uid) {
157
158
        $this->uid = $uid;
159
160
        return $this;
161
162
    }
163
164
    /**
165
     * Get parent unique id
166
     *
167
     * @return int
168
     */
169
    public function getParentUid() {
170
171
        return $this->parent_uid;
172
173
    }
174
175
    public function setParentUid($uid) {
176
177
        $this->parent_uid = $uid;
178
179
        return $this;
180
181
    }
182
183
    /**
184
     * Get current job id
185
     *
186
     * @return int
187
     */
188
    public function getJid() {
189
190
        return $this->jid;
191
192
    }
193
194
    public function setJid($jid) {
195
196
        $this->jid = $jid;
197
198
        return $this;
199
200
    }
201
202
    /**
203
     * Get requested niceness (-20/20)
204
     *
205
     * @return int
206
     */
207
    public function getNiceness() {
208
209
        return $this->niceness;
210
211
    }
212
213
    public function setNiceness($niceness) {
214
215
        $this->niceness = Validator::niceness($niceness);
216
217
        return $this;
218
219
    }
220
221
    /**
222
     * Get max allowed execution time
223
     *
224
     * @return int
225
     */
226
    public function getMaxtime() {
227
228
        return $this->maxtime;
229
230
    }
231
232
    public function setMaxtime($maxtime) {
233
234
        $this->maxtime = Validator::maxChildRuntime($maxtime);
235
236
        return $this;
237
238
    }
239
240
    /**
241
     * Get parameters
242
     *
243
     * @return TaskParameters
244
     */
245
    public function getParameters() {
246
247
        return $this->parameters;
248
249
    }
250
251
    public function setParameters(TaskParameters $parameters = null) {
252
253
        $this->parameters = is_null($parameters) ? new TaskParameters() : $parameters;
254
255
        return $this;
256
257
    }
258
259
    /**
260
     * Get start timestamp (microseconds)
261
     *
262
     * @return float
263
     */
264
    public function getStartTimestamp() {
265
266
        return $this->start_timestamp;
267
268
    }
269
270
    public function setStartTimestamp($time) {
271
272
        $this->start_timestamp = $time;
273
274
        return $this;
275
276
    }
277
278
    /**
279
     * Get pid
280
     *
281
     * @return int
282
     */
283
    public function getPid() {
284
285
        return $this->pid;
286
287
    }
288
289
    public function setPid($pid) {
290
291
        $this->pid = $pid;
292
293
        return $this;
294
295
    }
296
297
    public function hasOnDone() {
298
299
        return $this->done !== null;
300
301
    }
302
303
    public function getOnDone() {
304
305
        return $this->done;
306
307
    }
308
309
    public function onDone(Request $request = null) {
310
311
        $this->done = $request;
312
313
        return $this;
314
315
    }
316
317
    public function hasOnFail() {
318
319
        return $this->fail !== null;
320
321
    }
322
323
    public function getOnFail() {
324
325
        return $this->fail;
326
327
    }
328
329
    public function onFail(Request $request = null) {
330
331
        $this->fail = $request;
332
333
        return $this;
334
335
    }
336
337
    public function hasPipe() {
338
339
        return $this->pipe !== null;
340
341
    }
342
343
    public function getPipe() {
344
345
        return $this->pipe;
346
347
    }
348
349
    public function pipe(Request $request = null) {
350
351
        $this->pipe = $request;
352
353
        return $this;
354
355
    }
356
357
    public function isChain() {
358
359
        return ( $this->done !== null || $this->fail !== null || $this->pipe !== null );
360
361
    }
362
363
    public static function create($name, $task, TaskParameters $parameters = null) {
364
365
        return new Request($name, $task, $parameters);
366
367
    }
368
369
}
370