Completed
Push — master ( 2907e3...b9c0fa )
by Alexandre
02:14
created

Message::setNumRetries()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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