Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
89 / 89
100.00% covered (success)
100.00%
51 / 51
CRAP
100.00% covered (success)
100.00%
1 / 1
Task
100.00% covered (success)
100.00%
89 / 89
100.00% covered (success)
100.00%
51 / 51
51
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 create
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setTaskId
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getTaskId
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 hasTaskId
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setCron
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getCron
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 cron
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 schedule
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 setBuffer
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 buffer
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getBuffer
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 hasCron
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getSeconds
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getMinutes
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getHours
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getDaysOfTheMonth
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getMonths
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getDaysOfTheWeek
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 everySecond
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 every5Seconds
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 every10Seconds
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 every15Seconds
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 every20Seconds
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 every30Seconds
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 seconds
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 everyMinute
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 every5Minutes
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 every10Minutes
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 every15Minutes
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 every20Minutes
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 every30Minutes
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 minutes
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 hours
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 hourly
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 daily
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 dailyAt
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 weekly
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 monthly
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 quarterly
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 yearly
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 weekdays
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 weekends
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 sundays
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 mondays
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 tuesdays
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 wednesdays
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 thursdays
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 fridays
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 saturdays
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 between
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2/**
3 * Pop PHP Framework (http://www.popphp.org/)
4 *
5 * @link       https://github.com/popphp/popphp-framework
6 * @author     Nick Sagona, III <dev@nolainteractive.com>
7 * @copyright  Copyright (c) 2009-2024 NOLA Interactive, LLC. (http://www.nolainteractive.com)
8 * @license    http://www.popphp.org/license     New BSD License
9 */
10
11/**
12 * @namespace
13 */
14namespace Pop\Queue\Process;
15
16use Pop\Queue\Queue;
17
18/**
19 * Task class
20 *
21 * @category   Pop
22 * @package    Pop\Queue
23 * @author     Nick Sagona, III <dev@nolainteractive.com>
24 * @copyright  Copyright (c) 2009-2024 NOLA Interactive, LLC. (http://www.nolainteractive.com)
25 * @license    http://www.popphp.org/license     New BSD License
26 * @version    2.0.0
27 */
28class Task extends Job
29{
30
31    /**
32     * The cron Task
33     * @var ?Cron
34     */
35    protected ?Cron $cron = null;
36
37    /**
38     * Max attempts
39     * @var int
40     */
41    protected int $maxAttempts = 0;
42
43    /**
44     * Constructor
45     *
46     * Instantiate the job object
47     *
48     * @param  mixed   $callable
49     * @param  mixed   $params
50     * @param  ?string $id
51     * @param  Cron    $cron
52     */
53    public function __construct(mixed $callable = null, mixed $params = null, ?string $id = null, Cron $cron = new Cron())
54    {
55        parent::__construct($callable, $params, $id);
56        $this->setCron($cron);
57    }
58
59    /**
60     * Create task
61     *
62     * @param mixed   $callable
63     * @param mixed   $params
64     * @param ?string $id
65     * @param Cron    $cron
66     * @return Task
67     */
68    public static function create(
69        mixed $callable = null, mixed $params = null, ?string $id = null, Cron $cron = new Cron()
70    ): Task
71    {
72        return new self($callable, $params, $id, $cron);
73    }
74
75    /**
76     * Set task ID (alias)
77     *
78     * @param  string $id
79     * @return Task
80     */
81    public function setTaskId(string $id): Task
82    {
83        $this->setJobId($id);
84        return $this;
85    }
86
87    /**
88     * Get task id (alias)
89     *
90     * @return ?string
91     */
92    public function getTaskId(): ?string
93    {
94        return $this->getJobId();
95    }
96
97    /**
98     * Has task ID (alias)
99     *
100     * @return bool
101     */
102    public function hasTaskId(): bool
103    {
104        return $this->hasJobId();
105    }
106
107    /**
108     * Set cron Task
109     *
110     * @param  Cron $cron
111     * @return Task
112     */
113    public function setCron(Cron $cron): Task
114    {
115        $this->cron = $cron;
116        return $this;
117    }
118
119    /**
120     * Get cron Task
121     *
122     * @return ?Cron
123     */
124    public function getCron(): ?Cron
125    {
126        return $this->cron;
127    }
128
129    /**
130     * Get cron Task (alias)
131     *
132     * @return ?Cron
133     */
134    public function cron(): ?Cron
135    {
136        return $this->cron;
137    }
138
139    /**
140     * Schedule cront
141     *
142     * @param  $schedule
143     * @return Task
144     */
145    public function schedule(string $schedule): Task
146    {
147        $this->cron->schedule($schedule);
148        return $this;
149    }
150
151    /**
152     * Set time buffer
153     *
154     * @param  int $buffer
155     * @return Task
156     */
157    public function setBuffer(int $buffer): Task
158    {
159        $this->cron->setBuffer($buffer);
160        return $this;
161    }
162
163    /**
164     * Set time buffer (alias)
165     *
166     * @param  int $buffer
167     * @return Task
168     */
169    public function buffer(int $buffer): Task
170    {
171        $this->cron->setBuffer($buffer);
172        return $this;
173    }
174
175    /**
176     * Get time buffer
177     *
178     * @return int
179     */
180    public function getBuffer(): int
181    {
182        return $this->cron->getBuffer();
183    }
184
185    /**
186     * Has cron Task
187     *
188     * @return bool
189     */
190    public function hasCron(): bool
191    {
192        return ($this->cron !== null);
193    }
194
195    /**
196     * Get seconds
197     *
198     * @return array
199     */
200    public function getSeconds(): array
201    {
202        return $this->cron->getSeconds();
203    }
204
205    /**
206     * Get minutes
207     *
208     * @return array
209     */
210    public function getMinutes(): array
211    {
212        return $this->cron->getMinutes();
213    }
214
215    /**
216     * Get hours
217     *
218     * @return array
219     */
220    public function getHours(): array
221    {
222        return $this->cron->getHours();
223    }
224
225    /**
226     * Get days of the month
227     *
228     * @return array
229     */
230    public function getDaysOfTheMonth(): array
231    {
232        return $this->cron->getDaysOfTheMonth();
233    }
234
235    /**
236     * Get months
237     *
238     * @return array
239     */
240    public function getMonths(): array
241    {
242        return $this->cron->getMonths();
243    }
244
245    /**
246     * Get days of the week
247     *
248     * @return array
249     */
250    public function getDaysOfTheWeek(): array
251    {
252        return $this->cron->getDaysOfTheWeek();
253    }
254
255    /**
256     * Set job schedule to every second
257     *
258     * @return Task
259     */
260    public function everySecond(): Task
261    {
262        $this->cron->everySecond();
263        return $this;
264    }
265
266    /**
267     * Set job schedule to every 5 seconds
268     *
269     * @return Task
270     */
271    public function every5Seconds(): Task
272    {
273        $this->cron->every5Seconds();
274        return $this;
275    }
276
277    /**
278     * Set job schedule to every 10 seconds
279     *
280     * @return Task
281     */
282    public function every10Seconds(): Task
283    {
284
285        $this->cron->every10Seconds();
286        return $this;
287    }
288
289    /**
290     * Set job schedule to every 15 seconds
291     *
292     * @return Task
293     */
294    public function every15Seconds(): Task
295    {
296        $this->cron->every15Seconds();
297        return $this;
298    }
299
300    /**
301     * Set job schedule to every 20 seconds
302     *
303     * @return Task
304     */
305    public function every20Seconds(): Task
306    {
307        $this->cron->every20Seconds();
308        return $this;
309    }
310
311    /**
312     * Set job schedule to every 30 seconds
313     *
314     * @return Task
315     */
316    public function every30Seconds(): Task
317    {
318        $this->cron->every30Seconds();
319        return $this;
320    }
321
322    /**
323     * Set job schedule to by specific seconds
324     *
325     * @param  mixed $seconds
326     * @return Task
327     */
328    public function seconds(mixed $seconds): Task
329    {
330        $this->cron->seconds($seconds);
331        return $this;
332    }
333
334    /**
335     * Set job schedule to every minute
336     *
337     * @return Task
338     */
339    public function everyMinute(): Task
340    {
341        $this->cron->everyMinute();
342        return $this;
343    }
344
345    /**
346     * Set job schedule to every 5 minutes
347     *
348     * @return Task
349     */
350    public function every5Minutes(): Task
351    {
352        $this->cron->every5Minutes();
353        return $this;
354    }
355
356    /**
357     * Set job schedule to every 10 minutes
358     *
359     * @return Task
360     */
361    public function every10Minutes(): Task
362    {
363        $this->cron->every10Minutes();
364        return $this;
365    }
366
367    /**
368     * Set job schedule to every 15 minutes
369     *
370     * @return Task
371     */
372    public function every15Minutes(): Task
373    {
374        $this->cron->every15Minutes();
375        return $this;
376    }
377
378    /**
379     * Set job schedule to every 20 minutes
380     *
381     * @return Task
382     */
383    public function every20Minutes(): Task
384    {
385        $this->cron->every20Minutes();
386        return $this;
387    }
388
389    /**
390     * Set job schedule to every 30 minutes
391     *
392     * @return Task
393     */
394    public function every30Minutes(): Task
395    {
396        $this->cron->every30Minutes();
397        return $this;
398    }
399
400    /**
401     * Set job schedule to by specific minutes
402     *
403     * @param  mixed $minutes
404     * @return Task
405     */
406    public function minutes(mixed $minutes): Task
407    {
408        $this->cron->minutes($minutes);
409        return $this;
410    }
411
412    /**
413     * Set job schedule to by specific hours
414     *
415     * @param  mixed $hours
416     * @param  mixed $minutes
417     * @return Task
418     */
419    public function hours(mixed $hours, mixed $minutes = null): Task
420    {
421        $this->cron->hours($hours, $minutes);
422        return $this;
423    }
424
425    /**
426     * Set job schedule to hourly
427     *
428     * @param  mixed $minutes
429     * @return Task
430     */
431    public function hourly(mixed $minutes = null): Task
432    {
433        $this->cron->hourly($minutes);
434        return $this;
435    }
436
437    /**
438     * Set job schedule to daily
439     *
440     * @param  mixed $hours
441     * @param  mixed $minutes
442     * @return Task
443     */
444    public function daily(mixed $hours, mixed $minutes = null): Task
445    {
446        $this->cron->daily($hours, $minutes);
447        return $this;
448    }
449
450    /**
451     * Set job schedule to daily at specific time, i.e. 14:30
452     *
453     * @param  string $time
454     * @return Task
455     */
456    public function dailyAt(string $time): Task
457    {
458        $this->cron->dailyAt($time);
459        return $this;
460    }
461
462    /**
463     * Set job schedule to weekly
464     *
465     * @param  mixed $day
466     * @param  mixed $hours
467     * @param  mixed $minutes
468     * @return Task
469     */
470    public function weekly(mixed $day, mixed $hours = null, mixed $minutes = null): Task
471    {
472        $this->cron->weekly($day, $hours, $minutes);
473        return $this;
474    }
475
476    /**
477     * Set job schedule to monthly
478     *
479     * @param  mixed $day
480     * @param  mixed $hours
481     * @param  mixed $minutes
482     * @return Task
483     */
484    public function monthly(mixed $day, mixed $hours = null, mixed $minutes = null): Task
485    {
486        $this->cron->monthly($day, $hours, $minutes);
487        return $this;
488    }
489
490    /**
491     * Set job schedule to quarterly
492     *
493     * @param  mixed $hours
494     * @param  mixed $minutes
495     * @return Task
496     */
497    public function quarterly(mixed $hours = null, mixed $minutes = null): Task
498    {
499        $this->cron->quarterly($hours, $minutes);
500        return $this;
501    }
502
503    /**
504     * Set job schedule to yearly
505     *
506     * @param  bool $endOfYear
507     * @param  mixed $hours
508     * @param  mixed $minutes
509     * @return Task
510     */
511    public function yearly(bool $endOfYear = false, mixed $hours = null, mixed $minutes = null): Task
512    {
513        $this->cron->yearly($endOfYear, $hours, $minutes);
514        return $this;
515    }
516
517    /**
518     * Set job schedule to weekdays
519     *
520     * @return Task
521     */
522    public function weekdays(): Task
523    {
524        $this->cron->weekdays();
525        return $this;
526    }
527
528    /**
529     * Set job schedule to weekends
530     *
531     * @return Task
532     */
533    public function weekends(): Task
534    {
535        $this->cron->weekends();
536        return $this;
537    }
538
539    /**
540     * Set job schedule to Sundays
541     *
542     * @return Task
543     */
544    public function sundays(): Task
545    {
546        $this->cron->sundays();
547        return $this;
548    }
549
550    /**
551     * Set job schedule to Mondays
552     *
553     * @return Task
554     */
555    public function mondays(): Task
556    {
557        $this->cron->mondays();
558        return $this;
559    }
560
561    /**
562     * Set job schedule to Tuesdays
563     *
564     * @return Task
565     */
566    public function tuesdays(): Task
567    {
568        $this->cron->tuesdays();
569        return $this;
570    }
571
572    /**
573     * Set job schedule to Wednesdays
574     *
575     * @return Task
576     */
577    public function wednesdays(): Task
578    {
579        $this->cron->wednesdays();
580        return $this;
581    }
582
583    /**
584     * Set job schedule to Thursdays
585     *
586     * @return Task
587     */
588    public function thursdays(): Task
589    {
590        $this->cron->thursdays();
591        return $this;
592    }
593
594    /**
595     * Set job schedule to Fridays
596     *
597     * @return Task
598     */
599    public function fridays(): Task
600    {
601        $this->cron->fridays();
602        return $this;
603    }
604
605    /**
606     * Set job schedule to Saturdays
607     *
608     * @return Task
609     */
610    public function saturdays(): Task
611    {
612        $this->cron->saturdays();
613        return $this;
614    }
615
616    /**
617     * Set job schedule to between two hours
618     *
619     * @param  int $start
620     * @param  int $end
621     * @return Task
622     */
623    public function between(int $start, int $end): Task
624    {
625        $this->cron->between($start, $end);
626        return $this;
627    }
628
629}