Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions src/Console/Command/SeederCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
Expand Down Expand Up @@ -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);
}
}

Expand Down
8 changes: 7 additions & 1 deletion src/Database/Barry/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/Database/QueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
35 changes: 17 additions & 18 deletions src/Queue/Adapters/DatabaseAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
use Bow\Database\QueryBuilder;
use Bow\Queue\QueueTask;
use ErrorException;
use stdClass;
use Throwable;

class DatabaseAdapter extends QueueAdapter
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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;

Expand All @@ -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()) {
Expand All @@ -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')) {
Expand All @@ -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);

Expand Down Expand Up @@ -222,29 +221,29 @@ 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;
}

/**
* 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()),
]);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Queue/Adapters/RabbitMQAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
20 changes: 20 additions & 0 deletions src/Support/Log.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
Loading