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