Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
16 / 16
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
QueueRunCommand
100.00% covered (success)
100.00%
15 / 15
100.00% covered (success)
100.00%
3 / 3
5
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 configure
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 execute
100.00% covered (success)
100.00%
13 / 13
100.00% covered (success)
100.00%
1 / 1
3
1<?php
2
3declare(strict_types=1);
4
5/** @license For full copyright and license information, please see the LICENSE.md file. */
6
7namespace App\Core\Console\Command;
8
9defined('AMMONLY_APP') || exit('Direct script access is forbidden.');
10
11use App\Core\Cron\CronTaskInterface;
12use App\Modules\Automation\Queue\Task\ProcessQueueTask;
13use App\Modules\Mail\Task\ProcessMailQueueTask;
14use Symfony\Component\Console\Command\Command;
15use Symfony\Component\Console\Input\InputInterface;
16use Symfony\Component\Console\Output\OutputInterface;
17use Throwable;
18
19/**
20 * Queue Worker Console Command.
21 *
22 * @package App\Core\Console\Command
23 */
24final class QueueRunCommand extends Command
25{
26    /**
27     * QueueRunCommand constructor.
28     *
29     * @param CronTaskInterface|null $queueWorker Optional queue task worker.
30     * @param CronTaskInterface|null $mailWorker  Optional mail queue task worker.
31     */
32    public function __construct(
33        private ?CronTaskInterface $queueWorker = null,
34        private ?CronTaskInterface $mailWorker = null
35    ) {
36        parent::__construct('queue:run');
37    }
38
39    /** {@inheritdoc} */
40    protected function configure(): void
41    {
42        $this->setDescription('Executes all pending task queue jobs and mail queue items.');
43    }
44
45    /** {@inheritdoc} */
46    protected function execute(InputInterface $input, OutputInterface $output): int
47    {
48        $output->writeln('<info>[1/2] Processing general background task queue...</info>');
49        try {
50            $queueWorker = $this->queueWorker ?? new ProcessQueueTask();
51            $resQueue = $queueWorker->run();
52            $output->writeln("Result: {$resQueue}");
53        } catch (Throwable $e) {
54            $output->writeln("<comment>Queue bypass: {$e->getMessage()}</comment>");
55        }
56
57        $output->writeln('<info>[2/2] Processing outgoing email queue...</info>');
58        try {
59            $mailWorker = $this->mailWorker ?? new ProcessMailQueueTask();
60            $resMail = $mailWorker->run();
61            $output->writeln("Result: {$resMail}");
62        } catch (Throwable $e) {
63            $output->writeln("<comment>Mail queue bypass: {$e->getMessage()}</comment>");
64        }
65
66        return Command::SUCCESS;
67    }
68}