1 | <?php |
||
13 | class Queue |
||
14 | { |
||
15 | const DEFAULT_JOB_TIMEZONE = 'UTC'; |
||
16 | |||
17 | /** |
||
18 | * Client |
||
19 | * |
||
20 | * @var Client |
||
21 | */ |
||
22 | protected $client; |
||
23 | |||
24 | /** |
||
25 | * Name |
||
26 | * |
||
27 | * @var string |
||
28 | */ |
||
29 | protected $name; |
||
30 | |||
31 | /** |
||
32 | * Job marshaler |
||
33 | * |
||
34 | * @var MarshalerInterface |
||
35 | */ |
||
36 | private $marshaler; |
||
37 | |||
38 | /** |
||
39 | * Default time zone |
||
40 | * |
||
41 | * @var DateTimeZone |
||
42 | */ |
||
43 | private $timeZone; |
||
44 | |||
45 | /** |
||
46 | * Create a queue |
||
47 | * |
||
48 | * @param Client $client Client |
||
49 | * @param string $name Queue name |
||
50 | */ |
||
51 | 27 | public function __construct(Client $client, $name) |
|
57 | |||
58 | /** |
||
59 | * Get the queue name |
||
60 | * |
||
61 | * @return string |
||
62 | */ |
||
63 | 1 | public function getName() |
|
64 | { |
||
65 | 1 | return $this->name; |
|
66 | } |
||
67 | |||
68 | /** |
||
69 | * Set Job marshaler |
||
70 | * |
||
71 | * @param MarshalerInterface Marshaler |
||
72 | * @return void |
||
73 | */ |
||
74 | 27 | public function setMarshaler(MarshalerInterface $marshaler) |
|
78 | |||
79 | /** |
||
80 | * Pushes a job into the queue, setting it to be up for processing only at |
||
81 | * the specific date & time. |
||
82 | * |
||
83 | * @param JobInterface $job Job |
||
84 | * @param DateTime $when Date & time on when job should be ready for processing |
||
85 | * @param array $options ADDJOB options sent to the client |
||
86 | * @return JobInterface Job pushed |
||
87 | * @throws InvalidArgumentException |
||
88 | */ |
||
89 | 5 | public function schedule(JobInterface $job, DateTime $when, array $options = []) |
|
105 | |||
106 | /** |
||
107 | * Pushes a job into the queue |
||
108 | * |
||
109 | * @param JobInterface $job Job |
||
110 | * @param array $options ADDJOB options sent to the client |
||
111 | * @return JobInterface Job pushed |
||
112 | */ |
||
113 | 4 | public function push(JobInterface $job, array $options = []) |
|
120 | |||
121 | /** |
||
122 | * Pulls a single job from the queue (if none available, and if $timeout |
||
123 | * specified, then wait only this much time for a job, otherwise return |
||
124 | * `null`) |
||
125 | * |
||
126 | * @param int $timeout If specified, wait these many seconds |
||
127 | * @return Job|null A job, or null if no job was found before timeout |
||
128 | */ |
||
129 | 6 | public function pull($timeout = 0) |
|
151 | |||
152 | /** |
||
153 | * Marks that a Job is still being processed |
||
154 | * |
||
155 | * @param JobInterface $job Job |
||
156 | * @return int Number of seconds that the job visibility was postponed |
||
157 | */ |
||
158 | 2 | public function processing(JobInterface $job) |
|
163 | |||
164 | /** |
||
165 | * Acknowledges a Job as properly handled |
||
166 | * |
||
167 | * @param JobInterface $job Job |
||
168 | * @return void |
||
169 | */ |
||
170 | 2 | public function processed(JobInterface $job) |
|
175 | |||
176 | /** |
||
177 | * Marks the job as failed and returns it to the queue |
||
178 | * |
||
179 | * This increases the NACK counter of the job |
||
180 | * |
||
181 | * @param JobInterface $job |
||
182 | * @return void |
||
183 | */ |
||
184 | 2 | public function failed(JobInterface $job) |
|
189 | |||
190 | /** |
||
191 | * Check that we are connected to a node, and if not connect |
||
192 | * |
||
193 | * @return void |
||
194 | * @throws Disque\Connection\ConnectionException |
||
195 | */ |
||
196 | 16 | private function checkConnected() |
|
202 | } |
||
203 |