Skip to content

Commit

Permalink
feat: add queue:run command
Browse files Browse the repository at this point in the history
  • Loading branch information
mychidarko committed Sep 7, 2023
1 parent 42c4192 commit 7fff07a
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/Queue.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
];
}

Expand Down
40 changes: 40 additions & 0 deletions src/Queue/Commands/QueueRunCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace Leaf\Queue\Commands;

use Aloe\Command;
use Leaf\Queue;

class QueueRunCommand extends Command
{
protected static $defaultName = 'queue:run';
public $description = 'Start your queue worker';
public $help = 'Start your queue worker';

protected function handle()
{
$this->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;
}
}

0 comments on commit 7fff07a

Please sign in to comment.