From f940f691944a5af6145dfe91283e549bb5051b36 Mon Sep 17 00:00:00 2001 From: Franck DAKIA Date: Sat, 16 May 2026 22:40:08 +0000 Subject: [PATCH] Fix push the right queue name --- src/Console/Command/SeederCommand.php | 14 +++++------ src/Database/Barry/Model.php | 8 +++++- src/Database/QueryBuilder.php | 2 +- src/Queue/Adapters/DatabaseAdapter.php | 35 +++++++++++++------------- src/Queue/Adapters/RabbitMQAdapter.php | 2 +- src/Support/Log.php | 20 +++++++++++++++ 6 files changed, 52 insertions(+), 29 deletions(-) diff --git a/src/Console/Command/SeederCommand.php b/src/Console/Command/SeederCommand.php index 3d910071..8e78bddb 100644 --- a/src/Console/Command/SeederCommand.php +++ b/src/Console/Command/SeederCommand.php @@ -40,12 +40,14 @@ public function all(): void */ private function make(string $seed_filename, string $seeder_class_name): void { + $file_basename = basename($seed_filename); try { + echo Color::green("Seeding: seeders/$file_basename\n"); include_once $seed_filename; (new $seeder_class_name())->run(); - echo Color::green("Seeding completed: $seed_filename\n"); + echo Color::green("Seeded: seeders/$file_basename\n"); } catch (Exception $e) { - echo Color::red("Seeding failed for: $seed_filename"); + echo Color::red("Seeding failed for: seeders/$file_basename"); echo Color::red("\n" . $e->getMessage()); } } @@ -73,12 +75,8 @@ public function file(?string $seeder_class_name = null): void break; } - foreach ($seeder_files as $file => $seeder_class_name) { - echo Color::green("Seeding: $file"); - - $this->make($file, $seeder_class_name); - - echo Color::green("Seeding completed: $file"); + foreach ($seeder_files as $file => $_seeder_class_name) { + $this->make($file, $_seeder_class_name); } } diff --git a/src/Database/Barry/Model.php b/src/Database/Barry/Model.php index 93b4a389..09ddf4c2 100644 --- a/src/Database/Barry/Model.php +++ b/src/Database/Barry/Model.php @@ -22,10 +22,16 @@ use ReflectionClass; /** + * @method static as(string $as): Builder + * @method static whereRaw(string $where, array $data = []): Builder + * @method static join(string $table, string $first, mixed $comparator = '=', ?string $second = null): Builder + * @method static leftJoin(string $table, string $first, mixed $comparator = '=', ?string $second = null): Builder + * @method static rightJoin(string $table, string $first, mixed $comparator = '=', ?string $second = null): Builder + * @method static innerJoin(string $table, string $first, mixed $comparator = '=', ?string $second = null): Builder * @method static select(array|string[] $select): Builder * @method static whereIn(string $primary_key, array $id): Builder * @method static all(): Collection - * @method static where(string $column, mixed $value): Builder + * @method static where(string $column, mixed $comparator = '=', mixed $value = null): Builder * @method static orderBy(string $latest, string $string): Builder */ abstract class Model implements ArrayAccess, JsonSerializable diff --git a/src/Database/QueryBuilder.php b/src/Database/QueryBuilder.php index 4de4c469..dddd8c73 100644 --- a/src/Database/QueryBuilder.php +++ b/src/Database/QueryBuilder.php @@ -813,7 +813,7 @@ public function orOn(string $first, $comparator = '=', $second = null): QueryBui * @return QueryBuilder * @deprecated */ - public function group($column) + public function group(string $column) { return $this->groupBy($column); } diff --git a/src/Queue/Adapters/DatabaseAdapter.php b/src/Queue/Adapters/DatabaseAdapter.php index 5ebe9832..36db9093 100644 --- a/src/Queue/Adapters/DatabaseAdapter.php +++ b/src/Queue/Adapters/DatabaseAdapter.php @@ -9,7 +9,6 @@ use Bow\Database\QueryBuilder; use Bow\Queue\QueueTask; use ErrorException; -use stdClass; use Throwable; class DatabaseAdapter extends QueueAdapter @@ -69,9 +68,9 @@ public function push(QueueTask $task): bool $payload = [ "id" => $task->getId(), - "queue" => $this->getQueue(), + "queue" => $task->getQueue(), "payload" => base64_encode($this->serializeProducer($task)), - "attempts" => $this->tries, + "attempts" => $task->getRetry(), "status" => self::STATUS_WAITING, "available_at" => date("Y-m-d H:i:s", time() + (method_exists($task, 'getDelay') ? $task->getDelay() : 0)), "reserved_at" => null, @@ -122,10 +121,10 @@ private function fetchPendingJobs(string $queueName): array /** * Process a single task from the queue * - * @param stdClass $task + * @param \stdClass $task * @return void */ - private function processJob(stdClass $task): void + private function processJob(\stdClass $task): void { $producer = null; @@ -146,10 +145,10 @@ private function processJob(stdClass $task): void /** * Check if the task is ready to be processed * - * @param stdClass $task + * @param \stdClass $task * @return bool */ - private function isJobReady(stdClass $task): bool + private function isJobReady(\stdClass $task): bool { // Check if the task is available for processing if (strtotime($task->available_at) > time()) { @@ -168,11 +167,11 @@ private function isJobReady(stdClass $task): bool * Execute the task * * @param QueueTask $task - * @param stdClass $item + * @param \stdClass $item * @return void * @throws QueryBuilderException */ - private function executeTask(QueueTask $task, stdClass $item): void + private function executeTask(QueueTask $task, \stdClass $item): void { $this->logProcessingTask($task); if (!method_exists($task, 'process')) { @@ -187,12 +186,12 @@ private function executeTask(QueueTask $task, stdClass $item): void /** * Handle task failure * - * @param stdClass $task + * @param \stdClass $task * @param QueueTask|null $producer * @param Throwable $exception * @return void */ - private function handleJobFailure(stdClass $task, ?QueueTask $producer, Throwable $exception): void + private function handleJobFailure(\stdClass $task, ?QueueTask $producer, Throwable $exception): void { $this->logError($exception); @@ -222,10 +221,10 @@ private function handleJobFailure(stdClass $task, ?QueueTask $producer, Throwabl * Determine if the task should be marked as failed * * @param QueueTask $producer - * @param stdClass $task + * @param \stdClass $task * @return bool */ - private function shouldMarkJobAsFailed(QueueTask $producer, stdClass $task): bool + private function shouldMarkJobAsFailed(QueueTask $producer, \stdClass $task): bool { return $producer->taskShouldBeDelete() || $task->attempts <= 0; } @@ -233,18 +232,18 @@ private function shouldMarkJobAsFailed(QueueTask $producer, stdClass $task): boo /** * Schedule a task for retry * - * @param stdClass $task - * @param QueueTask $producer + * @param \stdClass $task + * @param QueueTask $queueTask * @return void * @throws QueryBuilderException */ - private function scheduleJobRetry(stdClass $task, QueueTask $producer): void + private function scheduleJobRetry(\stdClass $task, QueueTask $queueTask): void { $this->table->where("id", $task->id)->update([ "status" => self::STATUS_RESERVED, "attempts" => $task->attempts - 1, - "available_at" => date("Y-m-d H:i:s", time() + $producer->getDelay()), - "reserved_at" => date("Y-m-d H:i:s", time() + $producer->getRetry()), + "available_at" => date("Y-m-d H:i:s", time() + $queueTask->getDelay()), + "reserved_at" => date("Y-m-d H:i:s", time() + $queueTask->getRetry()), ]); } diff --git a/src/Queue/Adapters/RabbitMQAdapter.php b/src/Queue/Adapters/RabbitMQAdapter.php index dcc83cd0..86d0c63b 100644 --- a/src/Queue/Adapters/RabbitMQAdapter.php +++ b/src/Queue/Adapters/RabbitMQAdapter.php @@ -66,7 +66,7 @@ public function push(QueueTask $task): bool $msg = new AMQPMessage($body, [ 'delivery_mode' => AMQPMessage::DELIVERY_MODE_PERSISTENT ]); - $this->channel->basic_publish($msg, '', $this->queue); + $this->channel->basic_publish($msg, '', $task->getQueue()); return true; } diff --git a/src/Support/Log.php b/src/Support/Log.php index bc599707..52b5984a 100644 --- a/src/Support/Log.php +++ b/src/Support/Log.php @@ -9,9 +9,29 @@ * @method static void alert(string $message, array $context = []) * @method static void critical(string $message, array $context = []) * @method static void emergency(string $message, array $context = []) + * @method void error(string $message, array $context = []) + * @method void info(string $message, array $context = []) + * @method void warning(string $message, array $context = []) + * @method void alert(string $message, array $context = []) + * @method void critical(string $message, array $context = []) + * @method void emergency(string $message, array $context = []) */ class Log { + /** + * Log + * + * @param string $name + * @param array $arguments + * @return void + */ + public function __call(string $name, array $arguments = []) + { + $instance = app("logger"); + + call_user_func_array([$instance, $name], $arguments); + } + /** * Log *