-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQueue_Worker_Job.php
More file actions
84 lines (71 loc) · 1.4 KB
/
Copy pathQueue_Worker_Job.php
File metadata and controls
84 lines (71 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php
/**
* Job class file.
*
* @package Mantle
*/
namespace Mantle\Queue;
use Throwable;
/**
* Abstract Queue Worker Job
*
* Base class for provider-specific queue worker job classes.
*/
abstract class Queue_Worker_Job {
/**
* Flag if the job failed.
*/
public bool $failed = false;
/**
* Fire the queue job.
*/
abstract public function fire(): void;
/**
* Get the queue job ID.
*/
abstract public function get_id(): mixed;
/**
* Retrieve the stored job.
*/
abstract public function get_job(): mixed;
/**
* Handle a failed job.
*
* @param Throwable $e
*/
abstract public function failed( Throwable $e ): void;
/**
* Handle a completed job.
*/
abstract public function completed(): void;
/**
* Retry a job with a specified delay.
*
* @param int $delay Delay in seconds.
*/
abstract public function retry( int $delay = 0 ): void;
/**
* Delete a job from the queue.
*/
abstract public function delete(): void;
/**
* Check if the job has failed.
*/
public function has_failed(): bool {
return $this->failed;
}
/**
* Check if the job can be retried.
*/
public function can_retry(): bool {
return $this->has_failed() && ( $this->get_job()->retry ?? false );
}
/**
* Retrieve the retry backoff.
*
* @return int The retry backoff in seconds.
*/
public function get_retry_backoff(): int {
return $this->get_job()->retry_backoff ?? 0;
}
}