1 | <?php |
||
9 | class QueuePool |
||
10 | { |
||
11 | /** |
||
12 | * The command working path. |
||
13 | * |
||
14 | * @var string |
||
15 | */ |
||
16 | protected $commandPath; |
||
17 | |||
18 | /** |
||
19 | * The environment the workers should run under. |
||
20 | * |
||
21 | * @var string |
||
22 | */ |
||
23 | protected $environment; |
||
24 | |||
25 | /** |
||
26 | * The worker processes that started. |
||
27 | * |
||
28 | * @var array |
||
29 | */ |
||
30 | protected $processes; |
||
31 | |||
32 | /** |
||
33 | * The amount of seconds to wait before polling the queue. |
||
34 | * |
||
35 | * @var int |
||
36 | */ |
||
37 | protected $sleep = 3; |
||
38 | |||
39 | /** |
||
40 | * The amount of times to try a job before logging it failed. |
||
41 | * |
||
42 | * @var int |
||
43 | */ |
||
44 | protected $maxTries = 0; |
||
45 | |||
46 | /** |
||
47 | * The queue worker command line. |
||
48 | * |
||
49 | * @var string |
||
50 | */ |
||
51 | protected $workerCommand; |
||
52 | |||
53 | /** |
||
54 | * The output handler callback. |
||
55 | * |
||
56 | * @var \Closure|null |
||
57 | */ |
||
58 | protected $outputHandler; |
||
59 | |||
60 | /** |
||
61 | * Create a new queue listener. |
||
62 | * |
||
63 | * @param string $commandPath |
||
64 | * @return void |
||
|
|||
65 | */ |
||
66 | public function __construct($commandPath) |
||
71 | |||
72 | /** |
||
73 | * Build the environment specific worker command. |
||
74 | * |
||
75 | * @return string |
||
76 | */ |
||
77 | protected function buildCommandTemplate() |
||
83 | |||
84 | /** |
||
85 | * Get the PHP binary. |
||
86 | * |
||
87 | * @return string |
||
88 | */ |
||
89 | protected function phpBinary() |
||
95 | |||
96 | /** |
||
97 | * Get the Artisan binary. |
||
98 | * |
||
99 | * @return string |
||
100 | */ |
||
101 | protected function artisanBinary() |
||
107 | |||
108 | /** |
||
109 | * Start workers. |
||
110 | * |
||
111 | * @param string $connection |
||
112 | * @param string $queue |
||
113 | * @param QueuePoolOption $options |
||
114 | * @return void |
||
115 | */ |
||
116 | public function start($connection, $queue, QueuePoolOption $options) |
||
126 | |||
127 | /** |
||
128 | * Create an array of Symfony processes. |
||
129 | * |
||
130 | * @param $connection |
||
131 | * @param $queue |
||
132 | * @param QueuePoolOption $options |
||
133 | * @return array |
||
134 | */ |
||
135 | public function makeProcesses($connection, $queue, QueuePoolOption $options) |
||
145 | |||
146 | /** |
||
147 | * Create a new Symfony process for the worker. |
||
148 | * |
||
149 | * @param string $connection |
||
150 | * @param string $queue |
||
151 | * @param QueuePoolOption $options |
||
152 | * @return \Symfony\Component\Process\Process |
||
153 | */ |
||
154 | public function makeProcess($connection, $queue, QueuePoolOption $options) |
||
176 | |||
177 | /** |
||
178 | * Add the environment option to the given command. |
||
179 | * |
||
180 | * @param string $command |
||
181 | * @param QueuePoolOption $options |
||
182 | * @return string |
||
183 | */ |
||
184 | protected function addEnvironment($command, QueuePoolOption $options) |
||
188 | |||
189 | /** |
||
190 | * Format the given command with the listener options. |
||
191 | * |
||
192 | * @param $command |
||
193 | * @param $connection |
||
194 | * @param $queue |
||
195 | * @param QueuePoolOption $options |
||
196 | * @return string |
||
197 | */ |
||
198 | protected function formatCommand($command, $connection, $queue, QueuePoolOption $options) |
||
208 | |||
209 | /** |
||
210 | * Run worker processes. |
||
211 | * |
||
212 | * @param int $memory |
||
213 | * @return void |
||
214 | */ |
||
215 | public function runProcesses($memory) |
||
235 | |||
236 | /** |
||
237 | * Get processes. |
||
238 | * |
||
239 | * @return array |
||
240 | */ |
||
241 | public function getProcesses() |
||
245 | |||
246 | /** |
||
247 | * Set processes. |
||
248 | * |
||
249 | * @param array $processes |
||
250 | */ |
||
251 | public function setProcesses($processes) |
||
255 | |||
256 | /** |
||
257 | * Handle output from the worker process. |
||
258 | * |
||
259 | * @param int $type |
||
260 | * @param string $line |
||
261 | * @return void |
||
262 | */ |
||
263 | protected function handleWorkerOutput($type, $line) |
||
269 | |||
270 | /** |
||
271 | * Determine if the memory limit has been exceeded. |
||
272 | * |
||
273 | * @param int $memoryLimit |
||
274 | * @return bool |
||
275 | */ |
||
276 | public function memoryExceeded($memoryLimit) |
||
280 | |||
281 | /** |
||
282 | * Stop listening and bail out of the script. |
||
283 | * |
||
284 | * @return void |
||
285 | */ |
||
286 | public function stop() |
||
290 | |||
291 | /** |
||
292 | * Set the output handler callback. |
||
293 | * |
||
294 | * @param \Closure $outputHandler |
||
295 | * @return void |
||
296 | */ |
||
297 | public function setOutputHandler(\Closure $outputHandler) |
||
301 | } |
||
302 |
Adding a
@return
annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.