1 | <?php |
||
4 | class Job { |
||
5 | |||
6 | const STATE_ACTIVE = 'active'; |
||
7 | const STATE_WAIT_REPL = 'wait-repl'; |
||
8 | const STATE_QUEUED = 'queued'; |
||
9 | const STATE_ACKNOWLEDGED = 'acknowledged'; |
||
10 | |||
11 | /** |
||
12 | * Job Id (generated by disque). |
||
13 | * |
||
14 | * @var string |
||
15 | */ |
||
16 | private $id = ''; |
||
17 | |||
18 | |||
19 | /** |
||
20 | * Queue name this job was fetched from. |
||
21 | * |
||
22 | * @var string |
||
23 | */ |
||
24 | private $queue = ''; |
||
25 | |||
26 | |||
27 | /** |
||
28 | * Job body. |
||
29 | * |
||
30 | * @var string |
||
31 | */ |
||
32 | private $body = ''; |
||
33 | |||
34 | |||
35 | /** |
||
36 | * Delay time (before putting the job into the queue, in seconds). |
||
37 | * |
||
38 | * @var int |
||
39 | */ |
||
40 | private $delay = 0; |
||
41 | |||
42 | |||
43 | /** |
||
44 | * Retry time (seconds). |
||
45 | * |
||
46 | * How much time should elapse, since the last time the job was queued, and without an acknowledge about the job |
||
47 | * delivery, before the job is re-queued again for delivery. |
||
48 | * |
||
49 | * @var int |
||
50 | */ |
||
51 | private $retry = 120; |
||
52 | |||
53 | |||
54 | /** |
||
55 | * The expire time (in seconds). |
||
56 | * |
||
57 | * How much time should elapse for the job to be deleted regardless of the fact it was successfully delivered, |
||
58 | * i.e. acknowledged, or not. |
||
59 | * |
||
60 | * @var int |
||
61 | */ |
||
62 | private $ttl = 3600; |
||
63 | |||
64 | |||
65 | 20 | public function __construct($body) |
|
69 | |||
70 | |||
71 | /** |
||
72 | * Return the job id. |
||
73 | * |
||
74 | * @return string |
||
75 | */ |
||
76 | 16 | public function getId() |
|
80 | |||
81 | /** |
||
82 | * @param string $id |
||
83 | */ |
||
84 | 19 | public function setId($id) |
|
88 | |||
89 | /** |
||
90 | * @return string |
||
91 | */ |
||
92 | 18 | public function getBody() |
|
96 | |||
97 | /** |
||
98 | * @return int |
||
99 | */ |
||
100 | 17 | public function getDelay() |
|
104 | |||
105 | /** |
||
106 | * @param int $delay |
||
107 | */ |
||
108 | 1 | public function setDelay($delay) |
|
112 | |||
113 | /** |
||
114 | * @return int |
||
115 | */ |
||
116 | 17 | public function getRetry() |
|
120 | |||
121 | /** |
||
122 | * @param int $retry |
||
123 | */ |
||
124 | 4 | public function setRetry($retry) |
|
128 | |||
129 | /** |
||
130 | * @return int |
||
131 | */ |
||
132 | 17 | public function getTtL() |
|
136 | |||
137 | /** |
||
138 | * @param mixed $ttl |
||
139 | */ |
||
140 | 11 | public function setTtl($ttl) |
|
144 | |||
145 | /** |
||
146 | * @return string |
||
147 | */ |
||
148 | 2 | public function getQueue() |
|
152 | |||
153 | /** |
||
154 | * @param string $queue |
||
155 | */ |
||
156 | 17 | public function setQueue($queue) |
|
160 | |||
161 | |||
162 | /** |
||
163 | * Job Factory method. |
||
164 | * |
||
165 | * @param array $args |
||
166 | * @return Job |
||
167 | */ |
||
168 | 19 | public static function create(array $args) |
|
191 | |||
192 | /** |
||
193 | * Retrieve the originating node id. |
||
194 | * |
||
195 | * @return string|null The node id of the node where the job was published |
||
196 | */ |
||
197 | 1 | public function getOriginNode() |
|
201 | |||
202 | 1 | public function __toString() |
|
206 | } |
||
207 |