|
1
|
|
|
<?php |
|
2
|
|
|
namespace Disque\Queue; |
|
3
|
|
|
|
|
4
|
|
|
abstract class BaseJob implements JobInterface |
|
5
|
|
|
{ |
|
6
|
|
|
/** |
|
7
|
|
|
* Job ID |
|
8
|
|
|
* |
|
9
|
|
|
* @var string |
|
10
|
|
|
*/ |
|
11
|
|
|
protected $id; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* Job body |
|
15
|
|
|
* |
|
16
|
|
|
* This is the job data. Whether just an integer, an array, that depends |
|
17
|
|
|
* on the use case. |
|
18
|
|
|
* |
|
19
|
|
|
* @var mixed |
|
20
|
|
|
*/ |
|
21
|
|
|
protected $body; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* The name of the queue the job belongs to |
|
25
|
|
|
* |
|
26
|
|
|
* This is optional and can be null eg. when adding a new job. |
|
27
|
|
|
* It can however be used to identify what queue the job came from, |
|
28
|
|
|
* eg. in case of a consumer reading from multiple queues. |
|
29
|
|
|
* |
|
30
|
|
|
* @var string |
|
31
|
|
|
*/ |
|
32
|
|
|
protected $queue; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* The number of NACKs this job has received |
|
36
|
|
|
* |
|
37
|
|
|
* NACK is a command which tells Disque that the job wasn't processed |
|
38
|
|
|
* successfully and it should return to the queue immediately. |
|
39
|
|
|
* |
|
40
|
|
|
* @var int |
|
41
|
|
|
*/ |
|
42
|
|
|
protected $nacks = 0; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* The number of times this job has been re-delivered for reasons other |
|
46
|
|
|
* than a NACK |
|
47
|
|
|
* |
|
48
|
|
|
* @var int |
|
49
|
|
|
*/ |
|
50
|
|
|
protected $additionalDeliveries = 0; |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* An optional shortcut for instantiating the job with one call |
|
54
|
|
|
* |
|
55
|
|
|
* To make it more flexible, all arguments in the constructor are optional |
|
56
|
|
|
* and the job can be populated by calling the setters. |
|
57
|
|
|
* |
|
58
|
|
|
* @param mixed $body Body The job body |
|
59
|
|
|
* @param string $id The job ID |
|
60
|
|
|
* @param string $queue Name of the queue the job belongs to |
|
61
|
|
|
* @param int $nacks The number of NACKs |
|
62
|
|
|
* @param int $additionalDeliveries The number of additional deliveries |
|
63
|
|
|
*/ |
|
64
|
|
|
public function __construct( |
|
65
|
|
|
$body = null, |
|
66
|
|
|
$id = null, |
|
67
|
|
|
$queue = '', |
|
68
|
|
|
$nacks = 0, |
|
69
|
|
|
$additionalDeliveries = 0 |
|
70
|
|
|
) { |
|
71
|
|
|
$this->body = $body; |
|
72
|
|
|
$this->id = $id; |
|
73
|
|
|
$this->queue = $queue; |
|
74
|
|
|
$this->nacks = $nacks; |
|
75
|
|
|
$this->additionalDeliveries = $additionalDeliveries; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* @inheritdoc |
|
80
|
|
|
*/ |
|
81
|
|
|
public function getBody() |
|
82
|
|
|
{ |
|
83
|
|
|
return $this->body; |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* @inheritdoc |
|
88
|
|
|
*/ |
|
89
|
|
|
public function setBody($body) |
|
90
|
|
|
{ |
|
91
|
|
|
$this->body = $body; |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* @inheritdoc |
|
96
|
|
|
*/ |
|
97
|
|
|
public function getId() |
|
98
|
|
|
{ |
|
99
|
|
|
return $this->id; |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* @inheritdoc |
|
104
|
|
|
*/ |
|
105
|
|
|
public function setId($id) |
|
106
|
|
|
{ |
|
107
|
|
|
$this->id = $id; |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
/** |
|
111
|
|
|
* @inheritdoc |
|
112
|
|
|
*/ |
|
113
|
|
|
public function getQueue() |
|
114
|
|
|
{ |
|
115
|
|
|
return $this->queue; |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
/** |
|
119
|
|
|
* @inheritdoc |
|
120
|
|
|
*/ |
|
121
|
|
|
public function setQueue($queue) |
|
122
|
|
|
{ |
|
123
|
|
|
$this->queue = $queue; |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
/** |
|
127
|
|
|
* @inheritdoc |
|
128
|
|
|
*/ |
|
129
|
|
|
public function getNacks() |
|
130
|
|
|
{ |
|
131
|
|
|
return $this->nacks; |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
/** |
|
135
|
|
|
* @inheritdoc |
|
136
|
|
|
*/ |
|
137
|
|
|
public function setNacks($nacks) |
|
138
|
|
|
{ |
|
139
|
|
|
$this->nacks = $nacks; |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
/** |
|
143
|
|
|
* @inheritdoc |
|
144
|
|
|
*/ |
|
145
|
|
|
public function getAdditionalDeliveries() |
|
146
|
|
|
{ |
|
147
|
|
|
return $this->additionalDeliveries; |
|
148
|
|
|
} |
|
149
|
|
|
|
|
150
|
|
|
/** |
|
151
|
|
|
* @inheritdoc |
|
152
|
|
|
*/ |
|
153
|
|
|
public function setAdditionalDeliveries($additionalDeliveries) |
|
154
|
|
|
{ |
|
155
|
|
|
$this->additionalDeliveries = $additionalDeliveries; |
|
156
|
|
|
} |
|
157
|
|
|
} |
|
158
|
|
|
|