From 7fff07ae76d3f2150538c4ef3463b1fbbd506d2b Mon Sep 17 00:00:00 2001 From: mychidarko Date: Thu, 7 Sep 2023 21:29:31 +0000 Subject: [PATCH] feat: add queue:run command --- src/Queue.php | 3 +- src/Queue/Commands/QueueRunCommand.php | 40 ++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 src/Queue/Commands/QueueRunCommand.php diff --git a/src/Queue.php b/src/Queue.php index cd35699..d8ce74e 100644 --- a/src/Queue.php +++ b/src/Queue.php @@ -162,12 +162,13 @@ public function retryFailedJob($id, $retryCount = 0) /** * Return queue commands */ - public function commands() + public static function commands() { return [ \Leaf\Queue\Commands\DeleteJobCommand::class, \Leaf\Queue\Commands\GenerateJobCommand::class, \Leaf\Queue\Commands\QueuePauseCommand::class, + \Leaf\Queue\Commands\QueueRunCommand::class, ]; } diff --git a/src/Queue/Commands/QueueRunCommand.php b/src/Queue/Commands/QueueRunCommand.php new file mode 100644 index 0000000..14adde5 --- /dev/null +++ b/src/Queue/Commands/QueueRunCommand.php @@ -0,0 +1,40 @@ +writeln('Starting queue worker...'); + + $queue = new Queue; + $queueConfigFile = getcwd() . '/config/queue.php'; + $queueConfig = []; + + if (file_exists($queueConfigFile)) { + $queueConfig = require $queueConfigFile; + } + + if (empty($queueConfig)) { + if (!file_exists($configFile = getcwd() . '/queue.config.php')) { + throw new \Exception("Queue config not found"); + } + + $queueConfig = require $configFile; + } + + $queue->config($queueConfig); + $queue->connect(); + $queue->run(); + + return 0; + } +}