|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of HeriJobQueueBundle. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Alexandre Mogère |
|
7
|
|
|
* |
|
8
|
|
|
* This source file is subject to the MIT license that is bundled |
|
9
|
|
|
* with this source code in the file LICENSE. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Heri\Bundle\JobQueueBundle\Entity; |
|
13
|
|
|
|
|
14
|
|
|
use Doctrine\ORM\Mapping as ORM; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Heri\Bundle\JobQueueBundle\Entity\Message. |
|
18
|
|
|
* |
|
19
|
|
|
* @ORM\Table(name="queue_message") |
|
20
|
|
|
* @ORM\Entity |
|
21
|
|
|
* @ORM\HasLifecycleCallbacks |
|
22
|
|
|
*/ |
|
23
|
|
|
class Message |
|
24
|
|
|
{ |
|
25
|
|
|
/** |
|
26
|
|
|
* @var int |
|
27
|
|
|
* |
|
28
|
|
|
* @ORM\Column(name="id", type="integer", nullable=false) |
|
29
|
|
|
* @ORM\Id |
|
30
|
|
|
* @ORM\GeneratedValue(strategy="AUTO") |
|
31
|
|
|
*/ |
|
32
|
|
|
private $id; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @ORM\ManyToOne(targetEntity="Queue") |
|
36
|
|
|
*/ |
|
37
|
|
|
private $queue; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @var string |
|
41
|
|
|
* |
|
42
|
|
|
* @ORM\Column(name="handle", type="string", length=32, nullable=true) |
|
43
|
|
|
*/ |
|
44
|
|
|
private $handle; |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @var text |
|
48
|
|
|
* |
|
49
|
|
|
* @ORM\Column(name="body", type="text", nullable=false) |
|
50
|
|
|
*/ |
|
51
|
|
|
private $body; |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* @var string |
|
55
|
|
|
* |
|
56
|
|
|
* @ORM\Column(name="md5", type="string", length=32, nullable=false) |
|
57
|
|
|
*/ |
|
58
|
|
|
private $md5; |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* @var decimal |
|
62
|
|
|
* |
|
63
|
|
|
* @ORM\Column(name="timeout", type="decimal", nullable=true) |
|
64
|
|
|
*/ |
|
65
|
|
|
private $timeout; |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* @var int |
|
69
|
|
|
* |
|
70
|
|
|
* @ORM\Column(name="created", type="integer", nullable=false) |
|
71
|
|
|
*/ |
|
72
|
|
|
private $created; |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* @var smallint |
|
76
|
|
|
* |
|
77
|
|
|
* @ORM\Column(type = "smallint") |
|
78
|
|
|
*/ |
|
79
|
|
|
private $priority = 0; |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* @var bool |
|
83
|
|
|
* |
|
84
|
|
|
* @ORM\Column(name="failed", type="boolean", nullable=false) |
|
85
|
|
|
*/ |
|
86
|
|
|
private $failed; |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* @var int |
|
90
|
|
|
* |
|
91
|
|
|
* @ORM\Column(name="num_retries", type="integer", nullable=false) |
|
92
|
|
|
*/ |
|
93
|
|
|
private $numRetries = 0; |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* @var bool |
|
97
|
|
|
* |
|
98
|
|
|
* @ORM\Column(name="ended", type="boolean", nullable=false) |
|
99
|
|
|
*/ |
|
100
|
|
|
private $ended; |
|
101
|
|
|
|
|
102
|
|
|
/** @ORM\PrePersist */ |
|
103
|
|
|
public function prePersist() |
|
104
|
|
|
{ |
|
105
|
|
|
$this->md5 = md5($this->body); |
|
106
|
|
|
$this->created = time(); |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
public function __toString() |
|
110
|
|
|
{ |
|
111
|
|
|
return (string) $this->getId(); |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
/** |
|
115
|
|
|
* Get messageId. |
|
116
|
|
|
* |
|
117
|
|
|
* @return int |
|
118
|
|
|
*/ |
|
119
|
|
|
public function getId() |
|
120
|
|
|
{ |
|
121
|
|
|
return $this->id; |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
/** |
|
125
|
|
|
* Set handle. |
|
126
|
|
|
* |
|
127
|
|
|
* @param string $handle |
|
128
|
|
|
*/ |
|
129
|
|
|
public function setHandle($handle) |
|
130
|
|
|
{ |
|
131
|
|
|
$this->handle = $handle; |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
/** |
|
135
|
|
|
* Get handle. |
|
136
|
|
|
* |
|
137
|
|
|
* @return string |
|
138
|
|
|
*/ |
|
139
|
|
|
public function getHandle() |
|
140
|
|
|
{ |
|
141
|
|
|
return $this->handle; |
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
|
|
/** |
|
145
|
|
|
* Set body. |
|
146
|
|
|
* |
|
147
|
|
|
* @param text $body |
|
148
|
|
|
*/ |
|
149
|
|
|
public function setBody($body) |
|
150
|
|
|
{ |
|
151
|
|
|
$this->body = $body; |
|
152
|
|
|
} |
|
153
|
|
|
|
|
154
|
|
|
/** |
|
155
|
|
|
* Get body. |
|
156
|
|
|
* |
|
157
|
|
|
* @return text |
|
158
|
|
|
*/ |
|
159
|
|
|
public function getBody() |
|
160
|
|
|
{ |
|
161
|
|
|
return $this->body; |
|
162
|
|
|
} |
|
163
|
|
|
|
|
164
|
|
|
/** |
|
165
|
|
|
* Set md5. |
|
166
|
|
|
* |
|
167
|
|
|
* @param string $md5 |
|
168
|
|
|
*/ |
|
169
|
|
|
public function setMd5($md5) |
|
170
|
|
|
{ |
|
171
|
|
|
$this->md5 = $md5; |
|
172
|
|
|
} |
|
173
|
|
|
|
|
174
|
|
|
/** |
|
175
|
|
|
* Get md5. |
|
176
|
|
|
* |
|
177
|
|
|
* @return string |
|
178
|
|
|
*/ |
|
179
|
|
|
public function getMd5() |
|
180
|
|
|
{ |
|
181
|
|
|
return $this->md5; |
|
182
|
|
|
} |
|
183
|
|
|
|
|
184
|
|
|
/** |
|
185
|
|
|
* Set timeout. |
|
186
|
|
|
* |
|
187
|
|
|
* @param decimal $timeout |
|
188
|
|
|
*/ |
|
189
|
|
|
public function setTimeout($timeout) |
|
190
|
|
|
{ |
|
191
|
|
|
$this->timeout = $timeout; |
|
192
|
|
|
} |
|
193
|
|
|
|
|
194
|
|
|
/** |
|
195
|
|
|
* Get timeout. |
|
196
|
|
|
* |
|
197
|
|
|
* @return decimal |
|
198
|
|
|
*/ |
|
199
|
|
|
public function getTimeout() |
|
200
|
|
|
{ |
|
201
|
|
|
return $this->timeout; |
|
202
|
|
|
} |
|
203
|
|
|
|
|
204
|
|
|
/** |
|
205
|
|
|
* Set created. |
|
206
|
|
|
* |
|
207
|
|
|
* @param int $created |
|
208
|
|
|
*/ |
|
209
|
|
|
public function setCreated($created) |
|
210
|
|
|
{ |
|
211
|
|
|
$this->created = $created; |
|
212
|
|
|
} |
|
213
|
|
|
|
|
214
|
|
|
/** |
|
215
|
|
|
* Get created. |
|
216
|
|
|
* |
|
217
|
|
|
* @return int |
|
218
|
|
|
*/ |
|
219
|
|
|
public function getCreated() |
|
220
|
|
|
{ |
|
221
|
|
|
return $this->created; |
|
222
|
|
|
} |
|
223
|
|
|
|
|
224
|
|
|
/** |
|
225
|
|
|
* Set priority. |
|
226
|
|
|
* |
|
227
|
|
|
* @param smallint $priority |
|
228
|
|
|
*/ |
|
229
|
|
|
public function setPriority($priority) |
|
230
|
|
|
{ |
|
231
|
|
|
$this->priority = $priority; |
|
232
|
|
|
} |
|
233
|
|
|
|
|
234
|
|
|
/** |
|
235
|
|
|
* Get pririty. |
|
236
|
|
|
* |
|
237
|
|
|
* @return pririty |
|
238
|
|
|
*/ |
|
239
|
|
|
public function getPriority() |
|
240
|
|
|
{ |
|
241
|
|
|
return $this->priority; |
|
242
|
|
|
} |
|
243
|
|
|
|
|
244
|
|
|
/** |
|
245
|
|
|
* Set failed. |
|
246
|
|
|
* |
|
247
|
|
|
* @param bool $failed |
|
248
|
|
|
*/ |
|
249
|
|
|
public function setFailed($failed) |
|
250
|
|
|
{ |
|
251
|
|
|
$this->failed = $failed; |
|
252
|
|
|
} |
|
253
|
|
|
|
|
254
|
|
|
/** |
|
255
|
|
|
* Get failed. |
|
256
|
|
|
* |
|
257
|
|
|
* @return bool |
|
258
|
|
|
*/ |
|
259
|
|
|
public function getFailed() |
|
260
|
|
|
{ |
|
261
|
|
|
return $this->failed; |
|
262
|
|
|
} |
|
263
|
|
|
|
|
264
|
|
|
/** |
|
265
|
|
|
* Set ended. |
|
266
|
|
|
* |
|
267
|
|
|
* @param bool $ended |
|
268
|
|
|
*/ |
|
269
|
|
|
public function setEnded($ended) |
|
270
|
|
|
{ |
|
271
|
|
|
$this->ended = $ended; |
|
272
|
|
|
} |
|
273
|
|
|
|
|
274
|
|
|
/** |
|
275
|
|
|
* Get ended. |
|
276
|
|
|
* |
|
277
|
|
|
* @return bool |
|
278
|
|
|
*/ |
|
279
|
|
|
public function getEnded() |
|
280
|
|
|
{ |
|
281
|
|
|
return $this->ended; |
|
282
|
|
|
} |
|
283
|
|
|
|
|
284
|
|
|
public function toArray() |
|
285
|
|
|
{ |
|
286
|
|
|
return get_object_vars($this); |
|
287
|
|
|
} |
|
288
|
|
|
|
|
289
|
|
|
/** |
|
290
|
|
|
* Set queue. |
|
291
|
|
|
* |
|
292
|
|
|
* @param \Heri\Bundle\JobQueueBundle\Entity\Queue $queue |
|
293
|
|
|
* |
|
294
|
|
|
* @return Message |
|
295
|
|
|
*/ |
|
296
|
|
|
public function setQueue(\Heri\Bundle\JobQueueBundle\Entity\Queue $queue = null) |
|
297
|
|
|
{ |
|
298
|
|
|
$this->queue = $queue; |
|
299
|
|
|
|
|
300
|
|
|
return $this; |
|
301
|
|
|
} |
|
302
|
|
|
|
|
303
|
|
|
/** |
|
304
|
|
|
* Get queue. |
|
305
|
|
|
* |
|
306
|
|
|
* @return \Heri\Bundle\JobQueueBundle\Entity\Queue |
|
307
|
|
|
*/ |
|
308
|
|
|
public function getQueue() |
|
309
|
|
|
{ |
|
310
|
|
|
return $this->queue; |
|
311
|
|
|
} |
|
312
|
|
|
|
|
313
|
|
|
/** |
|
314
|
|
|
* @return int |
|
315
|
|
|
*/ |
|
316
|
|
|
public function getNumRetries() |
|
317
|
|
|
{ |
|
318
|
|
|
return $this->numRetries; |
|
319
|
|
|
} |
|
320
|
|
|
|
|
321
|
|
|
/** |
|
322
|
|
|
* @param int $numRetries |
|
323
|
|
|
*/ |
|
324
|
|
|
public function setNumRetries($numRetries) |
|
325
|
|
|
{ |
|
326
|
|
|
$this->numRetries = $numRetries; |
|
327
|
|
|
} |
|
328
|
|
|
} |
|
329
|
|
|
|