1 | <?php |
||
17 | class MongoThreadQueue extends Queue implements QueueContract |
||
18 | { |
||
19 | /** |
||
20 | * @var int |
||
21 | */ |
||
22 | protected $limit = 15; |
||
23 | |||
24 | /** |
||
25 | * Create a new database queue instance. |
||
26 | * |
||
27 | * @param Connection $database |
||
28 | * @param string $table |
||
29 | * @param string $default |
||
30 | * @param int $expire |
||
31 | * @param int $limit |
||
32 | */ |
||
33 | public function __construct(Connection $database, $table, $default = 'default', $expire = 60, $limit = 15) |
||
41 | |||
42 | /** |
||
43 | * Check if can run process depend on limits |
||
44 | * |
||
45 | * @param MongoJob $job |
||
46 | * |
||
47 | * @return bool |
||
48 | */ |
||
49 | public function canRunJob(MongoJob $job) |
||
60 | |||
61 | /** |
||
62 | * Get the next available job for the queue. |
||
63 | * |
||
64 | * @param $id |
||
65 | * |
||
66 | * @return null|MongoJob |
||
67 | */ |
||
68 | public function getJobById($id) |
||
80 | |||
81 | /** |
||
82 | * Push a new job onto the queue. |
||
83 | * |
||
84 | * @param string $job |
||
85 | * @param mixed $data |
||
86 | * @param string $queue |
||
87 | * |
||
88 | * @return mixed |
||
89 | */ |
||
90 | public function push($job, $data = '', $queue = null) |
||
94 | |||
95 | /** |
||
96 | * Push a new job onto the queue. |
||
97 | * |
||
98 | * @param string $job |
||
99 | * @param mixed $data |
||
100 | * @param string $queue |
||
101 | * |
||
102 | * @return mixed |
||
103 | */ |
||
104 | public function exists($job, $data = '', $queue = null) |
||
111 | |||
112 | /** |
||
113 | * Push a raw payload onto the queue. |
||
114 | * |
||
115 | * @param string $payload |
||
116 | * @param string $queue |
||
117 | * @param array $options |
||
118 | * |
||
119 | * @return mixed |
||
120 | */ |
||
121 | public function pushRaw($payload, $queue = null, array $options = []) |
||
125 | |||
126 | /** |
||
127 | * Push a new job onto the queue after a delay. |
||
128 | * |
||
129 | * @param DateTime|int $delay |
||
130 | * @param string $job |
||
131 | * @param mixed $data |
||
132 | * @param string $queue |
||
133 | * |
||
134 | * @return mixed |
||
135 | */ |
||
136 | public function later($delay, $job, $data = '', $queue = null) |
||
140 | |||
141 | /** |
||
142 | * Push an array of jobs onto the queue. |
||
143 | * |
||
144 | * @param array $jobs |
||
145 | * @param mixed $data |
||
146 | * @param string $queue |
||
147 | * |
||
148 | * @return mixed |
||
149 | */ |
||
150 | public function bulk($jobs, $data = '', $queue = null) |
||
162 | |||
163 | /** |
||
164 | * Release a reserved job back onto the queue. |
||
165 | * |
||
166 | * @param string $queue |
||
167 | * @param \StdClass $job |
||
168 | * @param int $delay |
||
169 | * |
||
170 | * @return mixed |
||
171 | */ |
||
172 | public function release($queue, $job, $delay) |
||
176 | |||
177 | /** |
||
178 | * Push a raw payload to the database with a given delay. |
||
179 | * |
||
180 | * @param DateTime|int $delay |
||
181 | * @param string|null $queue |
||
182 | * @param string $payload |
||
183 | * @param int $attempts |
||
184 | * |
||
185 | * @return mixed |
||
186 | */ |
||
187 | protected function pushToDatabase($delay, $queue, $payload, $attempts = 0) |
||
193 | |||
194 | /** |
||
195 | * Pop the next job off of the queue. |
||
196 | * |
||
197 | * @param string $queue |
||
198 | * |
||
199 | * @return Job|null |
||
200 | */ |
||
201 | public function pop($queue = null) |
||
212 | |||
213 | /** |
||
214 | * Get the next available job for the queue. |
||
215 | * |
||
216 | * @param string|null $queue |
||
217 | * |
||
218 | * @return null|MongoJob |
||
219 | */ |
||
220 | protected function getNextAvailableJob($queue) |
||
235 | |||
236 | /** |
||
237 | * Get available jobs |
||
238 | * |
||
239 | * @return array |
||
240 | */ |
||
241 | protected function isAvailable() |
||
248 | |||
249 | /** |
||
250 | * Get reserved but expired by time jobs |
||
251 | * |
||
252 | * @return array |
||
253 | */ |
||
254 | protected function isReservedButExpired() |
||
260 | |||
261 | /** |
||
262 | * Mark the given job ID as reserved. |
||
263 | * |
||
264 | * @param MongoJob $job |
||
265 | */ |
||
266 | public function markJobAsReserved($job) |
||
279 | |||
280 | /** |
||
281 | * Delete a reserved job from the queue. |
||
282 | * |
||
283 | * @param string $queue |
||
284 | * @param string $id |
||
285 | */ |
||
286 | public function deleteReserved($queue, $id) |
||
290 | |||
291 | /** |
||
292 | * Get the "available at" UNIX timestamp. |
||
293 | * |
||
294 | * @param DateTime|int $delay |
||
295 | * |
||
296 | * @return int |
||
297 | */ |
||
298 | protected function getAvailableAt($delay) |
||
304 | |||
305 | /** |
||
306 | * Create an array to insert for the given job. |
||
307 | * |
||
308 | * @param string|null $queue |
||
309 | * @param string $payload |
||
310 | * @param int $availableAt |
||
311 | * @param int $attempts |
||
312 | * |
||
313 | * @return array |
||
314 | */ |
||
315 | protected function buildDatabaseRecord($queue, $payload, $availableAt, $attempts = 0) |
||
327 | |||
328 | /** |
||
329 | * Get the queue or return the default. |
||
330 | * |
||
331 | * @param string|null $queue |
||
332 | * |
||
333 | * @return string |
||
334 | */ |
||
335 | protected function getQueue($queue) |
||
339 | |||
340 | /** |
||
341 | * Get the expiration time in seconds. |
||
342 | * |
||
343 | * @return int|null |
||
344 | */ |
||
345 | public function getExpire() |
||
349 | |||
350 | /** |
||
351 | * Set the expiration time in seconds. |
||
352 | * |
||
353 | * @param int|null $seconds |
||
354 | */ |
||
355 | public function setExpire($seconds) |
||
359 | |||
360 | /** |
||
361 | * Get the size of the queue. |
||
362 | * |
||
363 | * @param string $queue |
||
364 | * |
||
365 | * @return int |
||
366 | */ |
||
367 | public function size($queue = null) |
||
371 | |||
372 | /** |
||
373 | * Get queue table |
||
374 | * |
||
375 | * @return Collection Mongo collection instance |
||
376 | */ |
||
377 | protected function getCollection() |
||
381 | } |
||
382 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: