From d8ac053e55966a284c29abc5b5dd348cd5fe971f Mon Sep 17 00:00:00 2001 From: Sleon4 Date: Sun, 24 May 2026 11:43:38 -0500 Subject: [PATCH 1/6] xfix: Error capture when running queued tasks has been corrected --- routes/web.php | 8 +- .../Lion/Queue/RunQueuedTasksCommand.php | 93 +++++++++++-------- tests/Providers/ExampleProvider.php | 14 +++ 3 files changed, 71 insertions(+), 44 deletions(-) diff --git a/routes/web.php b/routes/web.php index 93e316a9..f7e9ed0a 100644 --- a/routes/web.php +++ b/routes/web.php @@ -20,6 +20,7 @@ use Dotenv\Dotenv; use Lion\Bundle\Enums\LogTypeEnum; use Lion\Bundle\Helpers\Commands\Queue\TaskQueue; +use Lion\Bundle\Support\Task; use Lion\Database\Driver; use Lion\Files\Store; use Lion\Route\Route; @@ -92,10 +93,9 @@ $taskQueue ->push( - new \Lion\Bundle\Support\Task(ExampleProvider::class, 'getArrExample', [ - 'name' => 'root', - ]), - new \Lion\Bundle\Support\Task(ExampleProvider::class, 'getResult') + new Task(ExampleProvider::class, 'getArrExample', ['name' => 'root']), + new Task(ExampleProvider::class, 'getResult'), + new Task(ExampleProvider::class, 'generateError') ); return info('[index]'); diff --git a/src/LionBundle/Commands/Lion/Queue/RunQueuedTasksCommand.php b/src/LionBundle/Commands/Lion/Queue/RunQueuedTasksCommand.php index 6297fe70..c69def37 100644 --- a/src/LionBundle/Commands/Lion/Queue/RunQueuedTasksCommand.php +++ b/src/LionBundle/Commands/Lion/Queue/RunQueuedTasksCommand.php @@ -13,6 +13,7 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; +use Throwable; /** * Allows queued tasks to run in the background. @@ -62,16 +63,16 @@ protected function configure(): void /** * Initializes the command after the input has been bound and before the - * input is validated + * input is validated. * * This is mainly useful when a lot of commands extends one main command * where some things need to be initialized based on the input arguments and - * options + * options. * - * @param InputInterface $input [InputInterface is the interface implemented - * by all input classes] - * @param OutputInterface $output [OutputInterface is the interface - * implemented by all Output classes] + * @param InputInterface $input InputInterface is the interface implemented + * by all input classes. + * @param OutputInterface $output OutputInterface is the interface + * implemented by all Output classes. * * @return void */ @@ -103,27 +104,27 @@ protected function initialize(InputInterface $input, OutputInterface $output): v } /** - * Executes the current command + * Executes the current command. * * This method is not abstract because you can use this class * as a concrete class. In this case, instead of defining the * execute() method, you set the code to execute by passing - * a Closure to the setCode() method + * a Closure to the setCode() method. * - * @param InputInterface $input [InputInterface is the interface implemented - * by all input classes] - * @param OutputInterface $output [OutputInterface is the interface - * implemented by all Output classes] + * @param InputInterface $input InputInterface is the interface implemented + * by all input classes. + * @param OutputInterface $output OutputInterface is the interface + * implemented by all Output classes. * * @return int * - * @throws LogicException [When this abstract method is not implemented] + * @throws LogicException When this abstract method is not implemented. * * @codeCoverageIgnore */ protected function execute(InputInterface $input, OutputInterface $output): int { - /** @var int|string $pause */ + /** @var string $pause */ $pause = $input->getOption('pause'); /** @phpstan-ignore-next-line */ @@ -131,7 +132,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $json = $this->taskQueue->get(); if (null === $json) { - $output->writeln($this->infoOutput("\t>> SCHEDULE: no queued tasks available")); + $output->writeln($this->infoOutput("\t>> SCHEDULE: no queued tasks available [OMITTED]")); $this->taskQueue->pause((int) $pause); @@ -152,32 +153,44 @@ protected function execute(InputInterface $input, OutputInterface $output): int ) ); - $return = $this->container->callMethod( - $this->container->resolve($queue['namespace']), - $queue['method'], - [ - 'queue' => $queue, - ...$queue['data'], - ], - ); - - if (is_object($return)) { - $return = (array) $return; + try { + $instance = $this->container->resolve($queue['namespace']); + + $instanceParams = ['queue' => $queue, ...$queue['data']]; + + $return = $this->container->callMethod($instance, $queue['method'], $instanceParams); + + if (is_object($return)) { + $return = (array) $return; + } + + $log = [ + 'class' => "{$queue['namespace']}::{$queue['method']}", + 'params' => $queue['data'], + 'return' => $return, + ]; + + logger("TASK: {$queue['id']}", LogTypeEnum::INFO, $log); + + $output->writeln($this->successOutput("\t>> SCHEDULE: {$queue['id']} / {$queue['namespace']}::{$queue['method']} [COMPLETED]")); // phpcs:ignore + } catch (Throwable $exception) { + logger( + "TASK: {$queue['id']}", + LogTypeEnum::ERROR, + [ + 'class' => "{$queue['namespace']}::{$queue['method']}", + 'params' => $queue['data'], + 'error' => [ + 'message' => $exception->getMessage(), + 'file' => $exception->getFile(), + 'line' => $exception->getLine(), + 'trace' => $exception->getTraceAsString(), + ], + ], + ); + + $output->writeln($this->errorOutput("\t>> SCHEDULE: {$queue['id']} / {$queue['namespace']}::{$queue['method']} [FAILED]")); // phpcs:ignore } - - $json = [ - 'class' => "{$queue['namespace']}::{$queue['method']}", - 'params' => $queue['data'], - 'return' => $return, - ]; - - logger("TASK: {$queue['id']}", LogTypeEnum::INFO, $json); - - $output->writeln( - $this->successOutput( - "\t>> SCHEDULE: {$queue['id']} / {$queue['namespace']}::{$queue['method']} [COMPLETED]" - ) - ); } } } diff --git a/tests/Providers/ExampleProvider.php b/tests/Providers/ExampleProvider.php index 803b22fa..7496ef5f 100644 --- a/tests/Providers/ExampleProvider.php +++ b/tests/Providers/ExampleProvider.php @@ -4,7 +4,9 @@ namespace Tests\Providers; +use Exception; use Lion\Helpers\Arr; +use Lion\Request\Http; use Lion\Route\Attributes\Rules; use stdClass; @@ -24,4 +26,16 @@ public function getResult(): stdClass { return success('Name: ' . request('name')); } + + /** + * Execute a sample exception. + * + * @return void + * + * @throws Exception + */ + public function generateError(): void + { + throw new Exception('ERR', Http::INTERNAL_SERVER_ERROR); + } } From f2e034a5508a2b583efe586cb1c22c66369dfd0d Mon Sep 17 00:00:00 2001 From: Sleon4 Date: Sun, 24 May 2026 13:44:13 -0500 Subject: [PATCH 2/6] chore: Support has been added to select databases in Redis for RunQueuedTasksCommand --- routes/web.php | 16 ++-- .../Lion/Queue/RunQueuedTasksCommand.php | 96 ++++++++++++------- .../Helpers/Commands/Queue/TaskQueue.php | 8 +- 3 files changed, 74 insertions(+), 46 deletions(-) diff --git a/routes/web.php b/routes/web.php index f7e9ed0a..90acb585 100644 --- a/routes/web.php +++ b/routes/web.php @@ -79,17 +79,19 @@ Route::addMiddleware(Routes::getMiddleware()); // ----------------------------------------------------------------------------- -Route::get('/', function (): stdClass { - /** @phpstan-ignore-next-line */ - $taskQueue = new TaskQueue([ +Route::get('/{database:i}', function (string $database): stdClass { + $data = [ 'scheme' => env('REDIS_SCHEME'), 'host' => env('REDIS_HOST'), 'port' => env('REDIS_PORT'), + 'database' => (int) $database, 'parameters' => [ 'password' => env('REDIS_PASSWORD'), - 'database' => TaskQueue::LION_DATABASE, ], - ]); + ]; + + /** @phpstan-ignore-next-line */ + $taskQueue = new TaskQueue($data); $taskQueue ->push( @@ -98,7 +100,9 @@ new Task(ExampleProvider::class, 'generateError') ); - return info('[index]'); + return info(message: '[index]', data: [ + 'database' => $database, + ]); }); Route::get('logger', function () { diff --git a/src/LionBundle/Commands/Lion/Queue/RunQueuedTasksCommand.php b/src/LionBundle/Commands/Lion/Queue/RunQueuedTasksCommand.php index c69def37..f41e9442 100644 --- a/src/LionBundle/Commands/Lion/Queue/RunQueuedTasksCommand.php +++ b/src/LionBundle/Commands/Lion/Queue/RunQueuedTasksCommand.php @@ -5,6 +5,7 @@ namespace Lion\Bundle\Commands\Lion\Queue; use DI\Attribute\Inject; +use JsonException; use Lion\Bundle\Enums\LogTypeEnum; use Lion\Bundle\Helpers\Commands\Queue\TaskQueue; use Lion\Bundle\Helpers\Commands\Selection\MenuCommand; @@ -34,6 +35,13 @@ class RunQueuedTasksCommand extends MenuCommand */ private TaskQueue $taskQueue; + /** + * Database in use. + * + * @var int $database + */ + private int $database; + #[Inject] public function setContainer(Container $container): RunQueuedTasksCommand { @@ -51,14 +59,9 @@ protected function configure(): void { $this ->setName('queue:run') - ->setDescription('Run queued tasks') - ->addOption( - 'pause', - 'p', - InputOption::VALUE_OPTIONAL, - 'Defines the time to wait before retrieving tasks if all have been executed.', - 60 - ); + ->setDescription('Run queued tasks.') + ->addOption('database', 'd', InputOption::VALUE_OPTIONAL, 'Redis database, default value 0 for internal operations.', TaskQueue::LION_DATABASE) // phpcs:ignore + ->addOption('pause', 'p', InputOption::VALUE_OPTIONAL, 'Defines the time to wait before retrieving tasks if all have been executed.', 60); // phpcs:ignore } /** @@ -80,6 +83,11 @@ protected function initialize(InputInterface $input, OutputInterface $output): v { parent::initialize($input, $output); + /** @var string $database */ + $database = $input->getOption('database'); + + $this->database = (int) $database; + /** @var string $redisScheme */ $redisScheme = env('REDIS_SCHEME'); @@ -96,9 +104,9 @@ protected function initialize(InputInterface $input, OutputInterface $output): v 'scheme' => $redisScheme, 'host' => $host, 'port' => $port, + 'database' => $this->database, 'parameters' => [ 'password' => $password, - 'database' => TaskQueue::LION_DATABASE, ], ]); } @@ -106,10 +114,9 @@ protected function initialize(InputInterface $input, OutputInterface $output): v /** * Executes the current command. * - * This method is not abstract because you can use this class - * as a concrete class. In this case, instead of defining the - * execute() method, you set the code to execute by passing - * a Closure to the setCode() method. + * This method is not abstract because you can use this class as a concrete + * class. In this case, instead of defining the execute() method, you set + * the code to execute by passing a Closure to the setCode() method. * * @param InputInterface $input InputInterface is the interface implemented * by all input classes. @@ -118,6 +125,7 @@ protected function initialize(InputInterface $input, OutputInterface $output): v * * @return int * + * @throws JsonException If encoding to JSON fails. * @throws LogicException When this abstract method is not implemented. * * @codeCoverageIgnore @@ -132,7 +140,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $json = $this->taskQueue->get(); if (null === $json) { - $output->writeln($this->infoOutput("\t>> SCHEDULE: no queued tasks available [OMITTED]")); + $output->writeln($this->infoOutput("\t>> TASK [DATABASE: {$this->database}]: There are no queued tasks available. [OMITTED]")); // phpcs:ignore $this->taskQueue->pause((int) $pause); @@ -147,11 +155,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int * } $queue */ $queue = json_decode($json, true); - $output->writeln( - $this->warningOutput( - "\t>> SCHEDULE: {$queue['id']} / {$queue['namespace']}::{$queue['method']} [PROCESSING]" - ) - ); + $output->writeln($this->warningOutput($this->getOutput('PROCESSING', $queue))); try { $instance = $this->container->resolve($queue['namespace']); @@ -172,25 +176,49 @@ protected function execute(InputInterface $input, OutputInterface $output): int logger("TASK: {$queue['id']}", LogTypeEnum::INFO, $log); - $output->writeln($this->successOutput("\t>> SCHEDULE: {$queue['id']} / {$queue['namespace']}::{$queue['method']} [COMPLETED]")); // phpcs:ignore + $output->writeln($this->successOutput($this->getOutput('COMPLETED', $queue))); } catch (Throwable $exception) { - logger( - "TASK: {$queue['id']}", - LogTypeEnum::ERROR, - [ - 'class' => "{$queue['namespace']}::{$queue['method']}", - 'params' => $queue['data'], - 'error' => [ - 'message' => $exception->getMessage(), - 'file' => $exception->getFile(), - 'line' => $exception->getLine(), - 'trace' => $exception->getTraceAsString(), - ], + $loggerData = [ + 'class' => "{$queue['namespace']}::{$queue['method']}", + 'params' => $queue['data'], + 'error' => [ + 'message' => $exception->getMessage(), + 'file' => $exception->getFile(), + 'line' => $exception->getLine(), + 'trace' => $exception->getTraceAsString(), ], - ); + ]; + + logger("TASK [DATABASE: {$this->database}]: {$queue['id']}", LogTypeEnum::ERROR, $loggerData); - $output->writeln($this->errorOutput("\t>> SCHEDULE: {$queue['id']} / {$queue['namespace']}::{$queue['method']} [FAILED]")); // phpcs:ignore + $output->writeln($this->errorOutput($this->getOutput('ERROR', $queue))); } } } + + /** + * @param string $type + * @param array{ + * id: string, + * namespace: string, + * method: string, + * data: array + * } $queue + * + * @return string + * + */ + private function getOutput(string $type, array $queue): string + { + /** @var string $id */ + $id = $queue['id']; + + /** @var string $namespace */ + $namespace = $queue['namespace']; + + /** @var string $method */ + $method = $queue['method']; + + return "\t>> TASK [DATABASE: {$this->database}]: {$id} / {$namespace}::{$method} [{$type}]"; + } } diff --git a/src/LionBundle/Helpers/Commands/Queue/TaskQueue.php b/src/LionBundle/Helpers/Commands/Queue/TaskQueue.php index 3779c137..eaaed5c1 100644 --- a/src/LionBundle/Helpers/Commands/Queue/TaskQueue.php +++ b/src/LionBundle/Helpers/Commands/Queue/TaskQueue.php @@ -15,15 +15,11 @@ class TaskQueue { /** * Defines the property that contains the queued task data. - * - * @const LION_TASKS */ public const string LION_TASKS = 'lion-tasks'; /** * Defines the database to connect to and manipulate tasks. - * - * @const LION_DATABASE */ public const int LION_DATABASE = 0; @@ -41,9 +37,9 @@ class TaskQueue * scheme: string, * host: string, * port: int, + * database: int, * parameters: array{ - * password: string, - * database: int + * password: string * } * } $parameters */ From 1567ddb6b0a71fdb6dad8a4d72b5519d69bb4d8e Mon Sep 17 00:00:00 2001 From: Sleon4 Date: Sun, 24 May 2026 14:29:18 -0500 Subject: [PATCH 3/6] feat: Constant support for the TaskQueue class is added --- routes/web.php | 8 ++- .../Lion/Queue/RunQueuedTasksCommand.php | 54 +++++++++---------- .../Helpers/Commands/Queue/TaskQueue.php | 15 ++++++ src/LionBundle/Support/Task.php | 2 - 4 files changed, 45 insertions(+), 34 deletions(-) diff --git a/routes/web.php b/routes/web.php index 90acb585..042d7c29 100644 --- a/routes/web.php +++ b/routes/web.php @@ -79,12 +79,12 @@ Route::addMiddleware(Routes::getMiddleware()); // ----------------------------------------------------------------------------- -Route::get('/{database:i}', function (string $database): stdClass { +Route::get('/', function (): stdClass { $data = [ 'scheme' => env('REDIS_SCHEME'), 'host' => env('REDIS_HOST'), 'port' => env('REDIS_PORT'), - 'database' => (int) $database, + 'database' => TaskQueue::LION_DATABASE, 'parameters' => [ 'password' => env('REDIS_PASSWORD'), ], @@ -100,9 +100,7 @@ new Task(ExampleProvider::class, 'generateError') ); - return info(message: '[index]', data: [ - 'database' => $database, - ]); + return info('[index]'); }); Route::get('logger', function () { diff --git a/src/LionBundle/Commands/Lion/Queue/RunQueuedTasksCommand.php b/src/LionBundle/Commands/Lion/Queue/RunQueuedTasksCommand.php index f41e9442..f4dd793c 100644 --- a/src/LionBundle/Commands/Lion/Queue/RunQueuedTasksCommand.php +++ b/src/LionBundle/Commands/Lion/Queue/RunQueuedTasksCommand.php @@ -82,33 +82,6 @@ protected function configure(): void protected function initialize(InputInterface $input, OutputInterface $output): void { parent::initialize($input, $output); - - /** @var string $database */ - $database = $input->getOption('database'); - - $this->database = (int) $database; - - /** @var string $redisScheme */ - $redisScheme = env('REDIS_SCHEME'); - - /** @var string $host */ - $host = env('REDIS_HOST'); - - /** @var int $port */ - $port = env('REDIS_PORT'); - - /** @var string $password */ - $password = env('REDIS_PASSWORD'); - - $this->taskQueue = new TaskQueue([ - 'scheme' => $redisScheme, - 'host' => $host, - 'port' => $port, - 'database' => $this->database, - 'parameters' => [ - 'password' => $password, - ], - ]); } /** @@ -135,6 +108,33 @@ protected function execute(InputInterface $input, OutputInterface $output): int /** @var string $pause */ $pause = $input->getOption('pause'); + /** @var string $database */ + $database = $input->getOption('database'); + + $this->database = (int) $database; + + /** @var string $redisScheme */ + $redisScheme = env('REDIS_SCHEME'); + + /** @var string $host */ + $host = env('REDIS_HOST'); + + /** @var int $port */ + $port = env('REDIS_PORT'); + + /** @var string $password */ + $password = env('REDIS_PASSWORD'); + + $this->taskQueue = new TaskQueue(parameters: [ + TaskQueue::SCHEME => $redisScheme, + TaskQueue::HOST => $host, + TaskQueue::PORT => $port, + TaskQueue::DATABASE => $this->database, + TaskQueue::PARAMETERS => [ + TaskQueue::PASSWORD => $password, + ], + ]); + /** @phpstan-ignore-next-line */ while (true) { $json = $this->taskQueue->get(); diff --git a/src/LionBundle/Helpers/Commands/Queue/TaskQueue.php b/src/LionBundle/Helpers/Commands/Queue/TaskQueue.php index eaaed5c1..768036c9 100644 --- a/src/LionBundle/Helpers/Commands/Queue/TaskQueue.php +++ b/src/LionBundle/Helpers/Commands/Queue/TaskQueue.php @@ -13,6 +13,21 @@ */ class TaskQueue { + /** + * Reference constants for Redis initialization. + */ + public const string SCHEME = 'scheme'; + + public const string HOST = 'host'; + + public const string PORT = 'port'; + + public const string DATABASE = 'database'; + + public const string PARAMETERS = 'parameters'; + + public const string PASSWORD = 'password'; + /** * Defines the property that contains the queued task data. */ diff --git a/src/LionBundle/Support/Task.php b/src/LionBundle/Support/Task.php index e75c65ac..697fd17a 100644 --- a/src/LionBundle/Support/Task.php +++ b/src/LionBundle/Support/Task.php @@ -8,8 +8,6 @@ /** * Tasks class to encapsulate tasks in queue. - * - * @package Lion\Bundle\Helpers\Commands\Schedule */ class Task { From 95f2857a267448023de4c90695e8a963f4694a80 Mon Sep 17 00:00:00 2001 From: Sleon4 Date: Sun, 24 May 2026 15:17:24 -0500 Subject: [PATCH 4/6] test: Test coverage is added --- tests/Commands/Lion/Queue/RunQueuedTasksCommandTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Commands/Lion/Queue/RunQueuedTasksCommandTest.php b/tests/Commands/Lion/Queue/RunQueuedTasksCommandTest.php index 5e11cfa8..d05a5e2e 100644 --- a/tests/Commands/Lion/Queue/RunQueuedTasksCommandTest.php +++ b/tests/Commands/Lion/Queue/RunQueuedTasksCommandTest.php @@ -68,8 +68,8 @@ public function initialize(): void 'output' => $output ]); - $taskQueue = $this->getPrivateProperty('taskQueue'); + $outputInstance = $this->getPrivateProperty('output'); - $this->assertInstanceOf(TaskQueue::class, $taskQueue); + $this->assertInstanceOf(BufferedOutput::class, $outputInstance); } } From b1f627e02dc682ec89650455137f463d2462a1f3 Mon Sep 17 00:00:00 2001 From: Sleon4 Date: Sun, 24 May 2026 15:32:32 -0500 Subject: [PATCH 5/6] feat: Reference constants for obtaining task data --- .../Lion/Queue/RunQueuedTasksCommand.php | 31 +++++++++++++------ src/LionBundle/Support/Task.php | 19 +++++++++--- 2 files changed, 37 insertions(+), 13 deletions(-) diff --git a/src/LionBundle/Commands/Lion/Queue/RunQueuedTasksCommand.php b/src/LionBundle/Commands/Lion/Queue/RunQueuedTasksCommand.php index f4dd793c..584e56f4 100644 --- a/src/LionBundle/Commands/Lion/Queue/RunQueuedTasksCommand.php +++ b/src/LionBundle/Commands/Lion/Queue/RunQueuedTasksCommand.php @@ -9,6 +9,7 @@ use Lion\Bundle\Enums\LogTypeEnum; use Lion\Bundle\Helpers\Commands\Queue\TaskQueue; use Lion\Bundle\Helpers\Commands\Selection\MenuCommand; +use Lion\Bundle\Support\Task; use Lion\Dependency\Injection\Container; use LogicException; use Symfony\Component\Console\Input\InputInterface; @@ -158,29 +159,41 @@ protected function execute(InputInterface $input, OutputInterface $output): int $output->writeln($this->warningOutput($this->getOutput('PROCESSING', $queue))); try { - $instance = $this->container->resolve($queue['namespace']); + /** @var string $id */ + $id = $queue[Task::ID]; - $instanceParams = ['queue' => $queue, ...$queue['data']]; + /** @var string $namespace */ + $namespace = $queue[Task::NAMESPACE]; - $return = $this->container->callMethod($instance, $queue['method'], $instanceParams); + /** @var string $method */ + $method = $queue['method']; + + /** @var array $data */ + $data = $queue[Task::DATA]; + + $instance = $this->container->resolve($namespace); + + $instanceParams = ['queue' => $queue, ...$data]; + + $return = $this->container->callMethod($instance, $method, $instanceParams); if (is_object($return)) { $return = (array) $return; } $log = [ - 'class' => "{$queue['namespace']}::{$queue['method']}", - 'params' => $queue['data'], + 'class' => "{$namespace}::{$method}", + 'params' => $data, 'return' => $return, ]; - logger("TASK: {$queue['id']}", LogTypeEnum::INFO, $log); + logger("TASK: {$id}", LogTypeEnum::INFO, $log); $output->writeln($this->successOutput($this->getOutput('COMPLETED', $queue))); } catch (Throwable $exception) { $loggerData = [ - 'class' => "{$queue['namespace']}::{$queue['method']}", - 'params' => $queue['data'], + 'class' => "{$namespace}::{$method}", + 'params' => $data, 'error' => [ 'message' => $exception->getMessage(), 'file' => $exception->getFile(), @@ -189,7 +202,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int ], ]; - logger("TASK [DATABASE: {$this->database}]: {$queue['id']}", LogTypeEnum::ERROR, $loggerData); + logger("TASK [DATABASE: {$this->database}]: {$id}", LogTypeEnum::ERROR, $loggerData); $output->writeln($this->errorOutput($this->getOutput('ERROR', $queue))); } diff --git a/src/LionBundle/Support/Task.php b/src/LionBundle/Support/Task.php index 697fd17a..3042c0eb 100644 --- a/src/LionBundle/Support/Task.php +++ b/src/LionBundle/Support/Task.php @@ -11,6 +11,17 @@ */ class Task { + /** + * Reference constants for obtaining task data. + */ + public const string ID = 'id'; + + public const string NAMESPACE = 'namespace'; + + public const string METHOD = 'method'; + + public const string DATA = 'data'; + /** * Property for namespace. * @@ -58,10 +69,10 @@ public function __construct(string $namespace, string $method, array $data = []) public function getTask(): string { return json([ - 'id' => uniqid('task-'), - 'namespace' => $this->namespace, - 'method' => $this->method, - 'data' => $this->data, + self::ID => uniqid('task-'), + self::NAMESPACE => $this->namespace, + self::METHOD => $this->method, + self::DATA => $this->data, ]); } } From 41dd92f91e363e484278b65858cf54717409e06b Mon Sep 17 00:00:00 2001 From: Sleon4 Date: Sun, 24 May 2026 15:39:50 -0500 Subject: [PATCH 6/6] test: Test coverage is added --- .../Commands/Lion/Queue/RunQueuedTasksCommand.php | 8 +++++++- tests/Commands/Lion/Queue/RunQueuedTasksCommandTest.php | 1 - 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/LionBundle/Commands/Lion/Queue/RunQueuedTasksCommand.php b/src/LionBundle/Commands/Lion/Queue/RunQueuedTasksCommand.php index 584e56f4..526cba12 100644 --- a/src/LionBundle/Commands/Lion/Queue/RunQueuedTasksCommand.php +++ b/src/LionBundle/Commands/Lion/Queue/RunQueuedTasksCommand.php @@ -168,13 +168,18 @@ protected function execute(InputInterface $input, OutputInterface $output): int /** @var string $method */ $method = $queue['method']; - /** @var array $data */ + /** + * @var array $data + * + * @phpstan-ignore-next-line + */ $data = $queue[Task::DATA]; $instance = $this->container->resolve($namespace); $instanceParams = ['queue' => $queue, ...$data]; + /** @phpstan-ignore-next-line */ $return = $this->container->callMethod($instance, $method, $instanceParams); if (is_object($return)) { @@ -220,6 +225,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int * * @return string * + * @codeCoverageIgnore */ private function getOutput(string $type, array $queue): string { diff --git a/tests/Commands/Lion/Queue/RunQueuedTasksCommandTest.php b/tests/Commands/Lion/Queue/RunQueuedTasksCommandTest.php index d05a5e2e..b7e49c9e 100644 --- a/tests/Commands/Lion/Queue/RunQueuedTasksCommandTest.php +++ b/tests/Commands/Lion/Queue/RunQueuedTasksCommandTest.php @@ -7,7 +7,6 @@ use DI\DependencyException; use DI\NotFoundException; use Lion\Bundle\Commands\Lion\Queue\RunQueuedTasksCommand; -use Lion\Bundle\Helpers\Commands\Queue\TaskQueue; use Lion\Dependency\Injection\Container; use Lion\Test\Test; use ReflectionException;