-
Notifications
You must be signed in to change notification settings - Fork 0
/
Queue.php
53 lines (47 loc) · 1.77 KB
/
Queue.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
namespace DS\Queue;
use DS\Queue\Consumer\Consumer;
use DS\Queue\Job\Job;
/**
* Stores Jobs in a...well, queue and then processes them using a Consumer
*
* A traditional queue interface uses push/pop. Here, the queue() function is
* pretty much the same as push. However, processNextJob() works more like a
* Visitor pattern. The idea is that you pass in a consumer which has a list of
* Tasks it knows how to perform and can also tell you what tasks those are by
* returning the Task Ids. The queue uses this information to look up a matching
* Job (by comparing its Task Id).
*
* There's a few benefits to this but the big one is that this is much easier
* to abstract for different queue backends. Some (*cough*Gearman*cough*) use
* callback systems that want to do the execution internally, while others have
* special handling for updating remote statues or removing them from queues.
* Since each queue backend is responsible for invoking the actual execution of
* the task, it's really easy to add extra handling around it.
*
* @author Ross Tuck <[email protected]>
*/
interface Queue {
/**
* Status code returned when no processable jobs were waiting in the queue
* @var string
*/
const RESULT_NO_JOB = 'no_job';
/**
* Add a job to the queue
*
* @param Job $job
*/
public function queue(Job $job);
/**
* Complete a job in the queue using the given consumer.
*
* Only Jobs that fall within the consumer's registered tasks will be
* processed, everything else will remain in the queue. On completion, the
* processed job or an appropriate result code will be returned.
*
* @param Consumer $consumer
* @return Job|string
*/
public function processNextJob(Consumer $consumer);
}