diff --git a/src/Commands/QueueClear.php b/src/Commands/QueueClear.php index 5d8e175..0080454 100644 --- a/src/Commands/QueueClear.php +++ b/src/Commands/QueueClear.php @@ -50,7 +50,8 @@ class QueueClear extends BaseCommand public function run(array $params) { // Read params - if (! $queue = array_shift($params)) { + $queue = array_shift($params); + if ($queue === null) { CLI::error('The queueName is not specified.'); return EXIT_ERROR; diff --git a/src/Commands/QueueForget.php b/src/Commands/QueueForget.php index 7a02ee3..df55a5d 100644 --- a/src/Commands/QueueForget.php +++ b/src/Commands/QueueForget.php @@ -50,7 +50,8 @@ class QueueForget extends BaseCommand public function run(array $params) { // Read params - if (! $id = array_shift($params)) { + $id = array_shift($params); + if ($id === null) { CLI::error('The ID of the failed job is not specified.'); return EXIT_ERROR; diff --git a/src/Commands/QueueRetry.php b/src/Commands/QueueRetry.php index 6bbb43b..ad993b5 100644 --- a/src/Commands/QueueRetry.php +++ b/src/Commands/QueueRetry.php @@ -59,7 +59,8 @@ class QueueRetry extends BaseCommand public function run(array $params) { // Read params - if (! $id = array_shift($params)) { + $id = array_shift($params); + if ($id === null) { CLI::error('The ID of the failed job is not specified.'); return EXIT_ERROR; diff --git a/src/Commands/QueueStop.php b/src/Commands/QueueStop.php index 91085d1..0becf7a 100644 --- a/src/Commands/QueueStop.php +++ b/src/Commands/QueueStop.php @@ -58,7 +58,8 @@ class QueueStop extends BaseCommand public function run(array $params) { // Read params - if (! $queue = array_shift($params)) { + $queue = array_shift($params); + if ($queue === null) { CLI::error('The queueName is not specified.'); return EXIT_ERROR; diff --git a/src/Commands/QueueWork.php b/src/Commands/QueueWork.php index 7f19bd8..18235c3 100644 --- a/src/Commands/QueueWork.php +++ b/src/Commands/QueueWork.php @@ -80,7 +80,8 @@ public function run(array $params) $waiting = false; // Read queue name from params - if (! $queue = array_shift($params)) { + $queue = array_shift($params); + if ($queue === null) { CLI::error('The queueName is not specified.'); return EXIT_ERROR; diff --git a/src/Handlers/PredisHandler.php b/src/Handlers/PredisHandler.php index 32f52f8..ea2267c 100644 --- a/src/Handlers/PredisHandler.php +++ b/src/Handlers/PredisHandler.php @@ -62,15 +62,22 @@ public function pop(string $queue, array $priorities): ?QueueJob $now = Time::now()->timestamp; foreach ($priorities as $priority) { - if ($tasks = $this->predis->zrangebyscore("queues:{$queue}:{$priority}", '-inf', $now, ['LIMIT' => [0, 1]])) { - if ($this->predis->zrem("queues:{$queue}:{$priority}", ...$tasks)) { + $tasks = $this->predis->zrangebyscore( + "queues:{$queue}:{$priority}", + '-inf', + $now, + ['LIMIT' => [0, 1]] + ); + if ($tasks !== []) { + $removed = $this->predis->zrem("queues:{$queue}:{$priority}", ...$tasks); + if ($removed !== 0) { break; } $tasks = []; } } - if (empty($tasks[0])) { + if ($tasks === []) { return null; } @@ -93,7 +100,11 @@ public function later(QueueJob $queueJob, int $seconds): bool $queueJob->status = Status::PENDING->value; $queueJob->available_at = Time::now()->addSeconds($seconds)->timestamp; - if ($result = $this->predis->zadd("queues:{$queueJob->queue}:{$queueJob->priority}", [json_encode($queueJob) => $queueJob->available_at->timestamp])) { + $result = $this->predis->zadd( + "queues:{$queueJob->queue}:{$queueJob->priority}", + [json_encode($queueJob) => $queueJob->available_at->timestamp] + ); + if ($result !== 0) { $this->predis->hdel("queues:{$queueJob->queue}::reserved", [$queueJob->id]); } @@ -131,14 +142,16 @@ public function done(QueueJob $queueJob, bool $keepJob): bool public function clear(?string $queue = null): bool { if ($queue !== null) { - if ($keys = $this->predis->keys("queues:{$queue}:*")) { + $keys = $this->predis->keys("queues:{$queue}:*"); + if ($keys !== []) { return $this->predis->del($keys) > 0; } return true; } - if ($keys = $this->predis->keys('queues:*')) { + $keys = $this->predis->keys('queues:*'); + if ($keys !== []) { return $this->predis->del($keys) > 0; } diff --git a/src/Handlers/RedisHandler.php b/src/Handlers/RedisHandler.php index 3036893..64f5562 100644 --- a/src/Handlers/RedisHandler.php +++ b/src/Handlers/RedisHandler.php @@ -89,7 +89,7 @@ public function pop(string $queue, array $priorities): ?QueueJob } } - if (empty($tasks[0])) { + if ($tasks === []) { return null; } @@ -114,7 +114,12 @@ public function later(QueueJob $queueJob, int $seconds): bool $queueJob->status = Status::PENDING->value; $queueJob->available_at = Time::now()->addSeconds($seconds)->timestamp; - if ($result = (int) $this->redis->zAdd("queues:{$queueJob->queue}:{$queueJob->priority}", $queueJob->available_at->timestamp, json_encode($queueJob))) { + $result = (int) $this->redis->zAdd( + "queues:{$queueJob->queue}:{$queueJob->priority}", + $queueJob->available_at->timestamp, + json_encode($queueJob) + ); + if ($result !== 0) { $this->redis->hDel("queues:{$queueJob->queue}::reserved", (string) $queueJob->id); }