@@ -66,7 +66,7 @@ |
||
66 | 66 | $class = get_class($this); |
67 | 67 | |
68 | 68 | preg_match('#\\\\Queue(.+)Task$#', $class, $matches); |
69 | - if (! $matches) { |
|
69 | + if (!$matches) { |
|
70 | 70 | throw new InvalidArgumentException('Invalid class name: ' . $class); |
71 | 71 | } |
72 | 72 |
@@ -17,7 +17,7 @@ discard block |
||
17 | 17 | use Queue\Shell\Task\QueueTaskInterface; |
18 | 18 | use RuntimeException; |
19 | 19 | use Throwable; |
20 | -declare(ticks = 1); |
|
20 | +declare(ticks=1); |
|
21 | 21 | |
22 | 22 | /** |
23 | 23 | * Main shell to init and run queue workers. |
@@ -121,7 +121,7 @@ discard block |
||
121 | 121 | if (in_array('Queue' . $name, $this->taskNames, true)) { |
122 | 122 | /** @var \Queue\Shell\Task\QueueTask|\Queue\Shell\Task\AddInterface $task */ |
123 | 123 | $task = $this->{'Queue' . $name}; |
124 | - if (! ($task instanceof AddInterface)) { |
|
124 | + if (!($task instanceof AddInterface)) { |
|
125 | 125 | $this->abort('This task does not support adding via CLI call'); |
126 | 126 | } |
127 | 127 | $task->add(); |
@@ -160,7 +160,7 @@ discard block |
||
160 | 160 | $pid = $this->_initPid(); |
161 | 161 | } catch (PersistenceFailedException $exception) { |
162 | 162 | $this->err($exception->getMessage()); |
163 | - $limit = (int) Configure::read('Queue.maxWorkers'); |
|
163 | + $limit = (int)Configure::read('Queue.maxWorkers'); |
|
164 | 164 | if ($limit) { |
165 | 165 | $this->out('Cannot start worker: Too many workers already/still running on this server (' . $limit . '/' . $limit . ')'); |
166 | 166 | } |
@@ -194,7 +194,7 @@ discard block |
||
194 | 194 | $startTime = time(); |
195 | 195 | $types = $this->_stringToArray($this->param('type')); |
196 | 196 | |
197 | - while (! $this->_exit) { |
|
197 | + while (!$this->_exit) { |
|
198 | 198 | $this->out(__d('queue', 'Looking for a job.'), 1, Shell::VERBOSE); |
199 | 199 | |
200 | 200 | $QueuedTask = $this->QueuedTasks->requestJob($this->_getTaskConf(), $types); |
@@ -214,7 +214,7 @@ discard block |
||
214 | 214 | $this->_exit = true; |
215 | 215 | $this->out('queue', 'Reached runtime of ' . (time() - $startTime) . ' Seconds (Max ' . Configure::readOrFail('Queue.workerMaxRuntime') . '), terminating.'); |
216 | 216 | } |
217 | - if ($this->_exit || mt_rand(0, 100) > (100 - (int) Config::gcprob())) { |
|
217 | + if ($this->_exit || mt_rand(0, 100) > (100 - (int)Config::gcprob())) { |
|
218 | 218 | $this->out(__d('queue', 'Performing old job cleanup.')); |
219 | 219 | $this->QueuedTasks->cleanOldJobs(); |
220 | 220 | } |
@@ -246,11 +246,11 @@ discard block |
||
246 | 246 | $data = unserialize($QueuedTask->data); |
247 | 247 | /** @var \Queue\Shell\Task\QueueTask $task */ |
248 | 248 | $task = $this->{$taskName}; |
249 | - if (! $task instanceof QueueTaskInterface) { |
|
249 | + if (!$task instanceof QueueTaskInterface) { |
|
250 | 250 | throw new RuntimeException('Task must implement ' . QueueTaskInterface::class); |
251 | 251 | } |
252 | 252 | |
253 | - $return = $task->run((array) $data, $QueuedTask->id); |
|
253 | + $return = $task->run((array)$data, $QueuedTask->id); |
|
254 | 254 | if ($return !== null) { |
255 | 255 | trigger_error('run() should be void and throw exception in error case now.', E_USER_DEPRECATED); |
256 | 256 | } |
@@ -259,7 +259,7 @@ discard block |
||
259 | 259 | $return = false; |
260 | 260 | |
261 | 261 | $failureMessage = get_class($e) . ': ' . $e->getMessage(); |
262 | - if (! ($e instanceof QueueException)) { |
|
262 | + if (!($e instanceof QueueException)) { |
|
263 | 263 | $failureMessage .= "\n" . $e->getTraceAsString(); |
264 | 264 | } |
265 | 265 | |
@@ -290,11 +290,11 @@ discard block |
||
290 | 290 | */ |
291 | 291 | public function clean() |
292 | 292 | { |
293 | - if (! Configure::read('Queue.cleanupTimeout')) { |
|
293 | + if (!Configure::read('Queue.cleanupTimeout')) { |
|
294 | 294 | $this->abort('You disabled cleanuptimout in config. Aborting.'); |
295 | 295 | } |
296 | 296 | |
297 | - $this->out('Deleting old jobs, that have finished before ' . date('Y-m-d H:i:s', time() - (int) Configure::read('Queue.cleanupTimeout'))); |
|
297 | + $this->out('Deleting old jobs, that have finished before ' . date('Y-m-d H:i:s', time() - (int)Configure::read('Queue.cleanupTimeout'))); |
|
298 | 298 | $this->QueuedTasks->cleanOldJobs(); |
299 | 299 | } |
300 | 300 | |
@@ -306,7 +306,7 @@ discard block |
||
306 | 306 | public function settings() |
307 | 307 | { |
308 | 308 | $this->out('Current Settings:'); |
309 | - $conf = (array) Configure::read('Queue'); |
|
309 | + $conf = (array)Configure::read('Queue'); |
|
310 | 310 | foreach ($conf as $key => $val) { |
311 | 311 | if ($val === false) { |
312 | 312 | $val = 'no'; |
@@ -355,7 +355,7 @@ discard block |
||
355 | 355 | public function getOptionParser() |
356 | 356 | { |
357 | 357 | $subcommandParser = [ |
358 | - 'options' => [ /* |
|
358 | + 'options' => [/* |
|
359 | 359 | * 'dry-run'=> array( |
360 | 360 | * 'short' => 'd', |
361 | 361 | * 'help' => 'Dry run the update, no jobs will actually be added.', |
@@ -406,7 +406,7 @@ discard block |
||
406 | 406 | */ |
407 | 407 | protected function _log($message, $pid = null, $addDetails = true) |
408 | 408 | { |
409 | - if (! Configure::read('Queue.log')) { |
|
409 | + if (!Configure::read('Queue.log')) { |
|
410 | 410 | return; |
411 | 411 | } |
412 | 412 | |
@@ -451,7 +451,7 @@ discard block |
||
451 | 451 | */ |
452 | 452 | protected function _getTaskConf() |
453 | 453 | { |
454 | - if (! is_array($this->_taskConf)) { |
|
454 | + if (!is_array($this->_taskConf)) { |
|
455 | 455 | $this->_taskConf = []; |
456 | 456 | foreach ($this->tasks as $task) { |
457 | 457 | list ($pluginName, $taskName) = pluginSplit($task); |
@@ -519,7 +519,7 @@ discard block |
||
519 | 519 | protected function _retrievePid() |
520 | 520 | { |
521 | 521 | if (function_exists('posix_getpid')) { |
522 | - $pid = (string) posix_getpid(); |
|
522 | + $pid = (string)posix_getpid(); |
|
523 | 523 | } else { |
524 | 524 | $pid = $this->QueuedTasks->key(); |
525 | 525 | } |
@@ -550,10 +550,10 @@ discard block |
||
550 | 550 | */ |
551 | 551 | protected function _deletePid($pid) |
552 | 552 | { |
553 | - if (! $pid) { |
|
553 | + if (!$pid) { |
|
554 | 554 | $pid = $this->_pid; |
555 | 555 | } |
556 | - if (! $pid) { |
|
556 | + if (!$pid) { |
|
557 | 557 | return; |
558 | 558 | } |
559 | 559 | } |
@@ -592,7 +592,7 @@ discard block |
||
592 | 592 | */ |
593 | 593 | protected function _stringToArray($param) |
594 | 594 | { |
595 | - if (! $param) { |
|
595 | + if (!$param) { |
|
596 | 596 | return []; |
597 | 597 | } |
598 | 598 |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | public static function defaultConnectionName() |
69 | 69 | { |
70 | 70 | $connection = Configure::read('Queue.connection'); |
71 | - if (! empty($connection)) { |
|
71 | + if (!empty($connection)) { |
|
72 | 72 | return $connection; |
73 | 73 | } |
74 | 74 | |
@@ -108,7 +108,7 @@ discard block |
||
108 | 108 | 'not_before' => $this->getDateTime() |
109 | 109 | ]; |
110 | 110 | |
111 | - if (! empty($notBefore)) { |
|
111 | + if (!empty($notBefore)) { |
|
112 | 112 | $task['not_before'] = $this->getDateTime(strtotime($notBefore)); |
113 | 113 | } |
114 | 114 | |
@@ -134,7 +134,7 @@ discard block |
||
134 | 134 | $conditions['task'] = $taskName; |
135 | 135 | } |
136 | 136 | |
137 | - return (bool) $this->find() |
|
137 | + return (bool)$this->find() |
|
138 | 138 | ->where($conditions) |
139 | 139 | ->select([ |
140 | 140 | 'id' |
@@ -194,7 +194,7 @@ discard block |
||
194 | 194 | { |
195 | 195 | $driverName = $this->_getDriverName(); |
196 | 196 | $options = [ |
197 | - 'fields' => function (Query $query) use ($driverName) { |
|
197 | + 'fields' => function(Query $query) use ($driverName) { |
|
198 | 198 | $alltime = $query->func()->avg('UNIX_TIMESTAMP(completed) - UNIX_TIMESTAMP(created)'); |
199 | 199 | $runtime = $query->func()->avg('UNIX_TIMESTAMP(completed) - UNIX_TIMESTAMP(fetched)'); |
200 | 200 | $fetchdelay = $query->func()->avg('UNIX_TIMESTAMP(fetched) - IF(not_before is NULL, UNIX_TIMESTAMP(created), UNIX_TIMESTAMP(not_before))'); |
@@ -241,7 +241,7 @@ discard block |
||
241 | 241 | public function getFullStats($taskName = null) |
242 | 242 | { |
243 | 243 | $driverName = $this->_getDriverName(); |
244 | - $fields = function (Query $query) use ($driverName) { |
|
244 | + $fields = function(Query $query) use ($driverName) { |
|
245 | 245 | $runtime = $query->newExpr('UNIX_TIMESTAMP(completed) - UNIX_TIMESTAMP(fetched)'); |
246 | 246 | switch ($driverName) { |
247 | 247 | case static::DRIVER_SQLSERVER: |
@@ -280,7 +280,7 @@ discard block |
||
280 | 280 | /** @var \DateTime $created */ |
281 | 281 | $created = $task['created']; |
282 | 282 | $day = $created->format('Y-m-d'); |
283 | - if (! isset($days[$day])) { |
|
283 | + if (!isset($days[$day])) { |
|
284 | 284 | $days[$day] = $day; |
285 | 285 | } |
286 | 286 | |
@@ -290,7 +290,7 @@ discard block |
||
290 | 290 | foreach ($result as $type => $tasks) { |
291 | 291 | foreach ($tasks as $day => $durations) { |
292 | 292 | $average = array_sum($durations) / count($durations); |
293 | - $result[$type][$day] = (int) $average; |
|
293 | + $result[$type][$day] = (int)$average; |
|
294 | 294 | } |
295 | 295 | |
296 | 296 | foreach ($days as $day) { |
@@ -377,13 +377,13 @@ discard block |
||
377 | 377 | } |
378 | 378 | |
379 | 379 | /** @var \Queue\Model\Entity\QueuedTask|null $task */ |
380 | - $task = $this->getConnection()->transactional(function () use ($query, $options, $now) { |
|
380 | + $task = $this->getConnection()->transactional(function() use ($query, $options, $now) { |
|
381 | 381 | $task = $query->find('all', $options) |
382 | 382 | ->enableAutoFields(true) |
383 | 383 | ->epilog('FOR UPDATE') |
384 | 384 | ->first(); |
385 | 385 | |
386 | - if (! $task) { |
|
386 | + if (!$task) { |
|
387 | 387 | return null; |
388 | 388 | } |
389 | 389 | |
@@ -396,7 +396,7 @@ discard block |
||
396 | 396 | return $this->saveOrFail($task); |
397 | 397 | }); |
398 | 398 | |
399 | - if (! $task) { |
|
399 | + if (!$task) { |
|
400 | 400 | return null; |
401 | 401 | } |
402 | 402 | |
@@ -417,7 +417,7 @@ discard block |
||
417 | 417 | ]; |
418 | 418 | $task = $this->patchEntity($task, $fields); |
419 | 419 | |
420 | - return (bool) $this->save($task); |
|
420 | + return (bool)$this->save($task); |
|
421 | 421 | } |
422 | 422 | |
423 | 423 | /** |
@@ -437,7 +437,7 @@ discard block |
||
437 | 437 | ]; |
438 | 438 | $task = $this->patchEntity($task, $fields); |
439 | 439 | |
440 | - return (bool) $this->save($task); |
|
440 | + return (bool)$this->save($task); |
|
441 | 441 | } |
442 | 442 | |
443 | 443 | /** |
@@ -496,12 +496,12 @@ discard block |
||
496 | 496 | */ |
497 | 497 | public function cleanOldJobs() |
498 | 498 | { |
499 | - if (! Configure::read('Queue.cleanuptimeout')) { |
|
499 | + if (!Configure::read('Queue.cleanuptimeout')) { |
|
500 | 500 | return; |
501 | 501 | } |
502 | 502 | |
503 | 503 | $this->deleteAll([ |
504 | - 'completed <' => time() - (int) Configure::read('Queue.cleanuptimeout') |
|
504 | + 'completed <' => time() - (int)Configure::read('Queue.cleanuptimeout') |
|
505 | 505 | ]); |
506 | 506 | } |
507 | 507 | |
@@ -540,7 +540,7 @@ discard block |
||
540 | 540 | return $this->_key; |
541 | 541 | } |
542 | 542 | $this->_key = sha1(microtime()); |
543 | - if (! $this->_key) { |
|
543 | + if (!$this->_key) { |
|
544 | 544 | throw new RuntimeException('Invalid key generated'); |
545 | 545 | } |
546 | 546 |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | $this->assertSame(0, $this->QueuedTasks->getLength()); |
70 | 70 | |
71 | 71 | // create a job |
72 | - $this->assertTrue((bool) $this->QueuedTasks->createJob('test1', [ |
|
72 | + $this->assertTrue((bool)$this->QueuedTasks->createJob('test1', [ |
|
73 | 73 | 'some' => 'random', |
74 | 74 | 'test' => 'data' |
75 | 75 | ])); |
@@ -78,15 +78,15 @@ discard block |
||
78 | 78 | $this->assertSame(1, $this->QueuedTasks->getLength()); |
79 | 79 | |
80 | 80 | // create some more jobs |
81 | - $this->assertTrue((bool) $this->QueuedTasks->createJob('test2', [ |
|
81 | + $this->assertTrue((bool)$this->QueuedTasks->createJob('test2', [ |
|
82 | 82 | 'some' => 'random', |
83 | 83 | 'test' => 'data2' |
84 | 84 | ])); |
85 | - $this->assertTrue((bool) $this->QueuedTasks->createJob('test2', [ |
|
85 | + $this->assertTrue((bool)$this->QueuedTasks->createJob('test2', [ |
|
86 | 86 | 'some' => 'random', |
87 | 87 | 'test' => 'data3' |
88 | 88 | ])); |
89 | - $this->assertTrue((bool) $this->QueuedTasks->createJob('test3', [ |
|
89 | + $this->assertTrue((bool)$this->QueuedTasks->createJob('test3', [ |
|
90 | 90 | 'some' => 'random', |
91 | 91 | 'test' => 'data4' |
92 | 92 | ])); |
@@ -132,7 +132,7 @@ discard block |
||
132 | 132 | // there are no jobs, so we cant fetch any. |
133 | 133 | $this->assertNull($this->QueuedTasks->requestJob($capabilities)); |
134 | 134 | // insert one job. |
135 | - $this->assertTrue((bool) $this->QueuedTasks->createJob('task1', $testData)); |
|
135 | + $this->assertTrue((bool)$this->QueuedTasks->createJob('task1', $testData)); |
|
136 | 136 | |
137 | 137 | // fetch and check the first job. |
138 | 138 | $job = $this->QueuedTasks->requestJob($capabilities); |
@@ -177,7 +177,7 @@ discard block |
||
177 | 177 | $this->assertSame(0, $this->QueuedTasks->getLength()); |
178 | 178 | // create some more jobs |
179 | 179 | foreach (range(0, 9) as $num) { |
180 | - $this->assertTrue((bool) $this->QueuedTasks->createJob('task1', [ |
|
180 | + $this->assertTrue((bool)$this->QueuedTasks->createJob('task1', [ |
|
181 | 181 | 'tasknum' => $num |
182 | 182 | ])); |
183 | 183 | } |
@@ -216,9 +216,9 @@ discard block |
||
216 | 216 | */ |
217 | 217 | public function testNotBefore() |
218 | 218 | { |
219 | - $this->assertTrue((bool) $this->QueuedTasks->createJob('task1', null, '+ 1 Min')); |
|
220 | - $this->assertTrue((bool) $this->QueuedTasks->createJob('task1', null, '+ 1 Day')); |
|
221 | - $this->assertTrue((bool) $this->QueuedTasks->createJob('task1', null, '2009-07-01 12:00:00')); |
|
219 | + $this->assertTrue((bool)$this->QueuedTasks->createJob('task1', null, '+ 1 Min')); |
|
220 | + $this->assertTrue((bool)$this->QueuedTasks->createJob('task1', null, '+ 1 Day')); |
|
221 | + $this->assertTrue((bool)$this->QueuedTasks->createJob('task1', null, '2009-07-01 12:00:00')); |
|
222 | 222 | $data = $this->QueuedTasks->find('all')->toArray(); |
223 | 223 | $this->assertWithinRange((new Time('+ 1 Min'))->toUnixString(), $data[0]['not_before']->toUnixString(), 60); |
224 | 224 | $this->assertWithinRange((new Time('+ 1 Day'))->toUnixString(), $data[1]['not_before']->toUnixString(), 60); |
@@ -247,16 +247,16 @@ discard block |
||
247 | 247 | 'retries' => 2 |
248 | 248 | ] |
249 | 249 | ]; |
250 | - $this->assertTrue((bool) $this->QueuedTasks->createJob('dummytask')); |
|
251 | - $this->assertTrue((bool) $this->QueuedTasks->createJob('dummytask')); |
|
250 | + $this->assertTrue((bool)$this->QueuedTasks->createJob('dummytask')); |
|
251 | + $this->assertTrue((bool)$this->QueuedTasks->createJob('dummytask')); |
|
252 | 252 | // create a task with it's execution target some seconds in the past, so it should jump to the top of the testCreateAndFetchlist. |
253 | - $this->assertTrue((bool) $this->QueuedTasks->createJob('task1', [ |
|
253 | + $this->assertTrue((bool)$this->QueuedTasks->createJob('task1', [ |
|
254 | 254 | 'three' |
255 | 255 | ], '- 3 Seconds')); |
256 | - $this->assertTrue((bool) $this->QueuedTasks->createJob('task1', [ |
|
256 | + $this->assertTrue((bool)$this->QueuedTasks->createJob('task1', [ |
|
257 | 257 | 'two' |
258 | 258 | ], '- 5 Seconds')); |
259 | - $this->assertTrue((bool) $this->QueuedTasks->createJob('task1', [ |
|
259 | + $this->assertTrue((bool)$this->QueuedTasks->createJob('task1', [ |
|
260 | 260 | 'one' |
261 | 261 | ], '- 7 Seconds')); |
262 | 262 | |
@@ -329,19 +329,19 @@ discard block |
||
329 | 329 | $data1 = [ |
330 | 330 | 'key' => 1 |
331 | 331 | ]; |
332 | - $this->assertTrue((bool) $this->QueuedTasks->createJob('task1', $data1)); |
|
332 | + $this->assertTrue((bool)$this->QueuedTasks->createJob('task1', $data1)); |
|
333 | 333 | $data2 = [ |
334 | 334 | 'key' => 2 |
335 | 335 | ]; |
336 | - $this->assertTrue((bool) $this->QueuedTasks->createJob('task1', $data2)); |
|
336 | + $this->assertTrue((bool)$this->QueuedTasks->createJob('task1', $data2)); |
|
337 | 337 | $data3 = [ |
338 | 338 | 'key' => 3 |
339 | 339 | ]; |
340 | - $this->assertTrue((bool) $this->QueuedTasks->createJob('task1', $data3)); |
|
341 | - $this->assertTrue((bool) $this->QueuedTasks->createJob('dummytask')); |
|
342 | - $this->assertTrue((bool) $this->QueuedTasks->createJob('dummytask')); |
|
343 | - $this->assertTrue((bool) $this->QueuedTasks->createJob('dummytask')); |
|
344 | - $this->assertTrue((bool) $this->QueuedTasks->createJob('dummytask')); |
|
340 | + $this->assertTrue((bool)$this->QueuedTasks->createJob('task1', $data3)); |
|
341 | + $this->assertTrue((bool)$this->QueuedTasks->createJob('dummytask')); |
|
342 | + $this->assertTrue((bool)$this->QueuedTasks->createJob('dummytask')); |
|
343 | + $this->assertTrue((bool)$this->QueuedTasks->createJob('dummytask')); |
|
344 | + $this->assertTrue((bool)$this->QueuedTasks->createJob('dummytask')); |
|
345 | 345 | |
346 | 346 | // At first we get task1-1. |
347 | 347 | $this->QueuedTasks->clearKey(); |
@@ -417,7 +417,7 @@ discard block |
||
417 | 417 | $data = [ |
418 | 418 | 'key' => '1' |
419 | 419 | ]; |
420 | - $this->assertTrue((bool) $this->QueuedTasks->createJob('task1', $data)); |
|
420 | + $this->assertTrue((bool)$this->QueuedTasks->createJob('task1', $data)); |
|
421 | 421 | |
422 | 422 | $this->QueuedTasks->clearKey(); |
423 | 423 | $tmp = $this->QueuedTasks->requestJob($capabilities); |
@@ -459,7 +459,7 @@ discard block |
||
459 | 459 | ] |
460 | 460 | ]; |
461 | 461 | |
462 | - $this->assertTrue((bool) $this->QueuedTasks->createJob('task1', [ |
|
462 | + $this->assertTrue((bool)$this->QueuedTasks->createJob('task1', [ |
|
463 | 463 | '1' |
464 | 464 | ])); |
465 | 465 |