diff --git a/app/Console/Commands/Schedule/ProcessRunnableCommand.php b/app/Console/Commands/Schedule/ProcessRunnableCommand.php index c11ade6c3..d773cb2b2 100644 --- a/app/Console/Commands/Schedule/ProcessRunnableCommand.php +++ b/app/Console/Commands/Schedule/ProcessRunnableCommand.php @@ -6,7 +6,6 @@ use Illuminate\Console\Command; use App\Models\Schedule; use Illuminate\Database\Eloquent\Builder; use App\Services\Schedules\ProcessScheduleService; -use Carbon\Carbon; class ProcessRunnableCommand extends Command { @@ -24,7 +23,7 @@ class ProcessRunnableCommand extends Command ->whereRelation('server', fn (Builder $builder) => $builder->whereNull('status')) ->where('is_active', true) ->where('is_processing', false) - ->where('next_run_at', '<=', Carbon::now()->toDateTimeString()) + ->where('next_run_at', '<=', now('UTC')->toDateTimeString()) ->get(); if ($schedules->count() < 1) { diff --git a/app/Helpers/Utilities.php b/app/Helpers/Utilities.php index e0c824d01..c810788cc 100644 --- a/app/Helpers/Utilities.php +++ b/app/Helpers/Utilities.php @@ -40,7 +40,7 @@ class Utilities { return Carbon::instance((new CronExpression( sprintf('%s %s %s %s %s', $minute, $hour, $dayOfMonth, $month, $dayOfWeek) - ))->getNextRunDate()); + ))->getNextRunDate(now('UTC'))); } public static function checked(string $name, mixed $default): string diff --git a/app/Models/Schedule.php b/app/Models/Schedule.php index ae7b9baec..d6d19a8e1 100644 --- a/app/Models/Schedule.php +++ b/app/Models/Schedule.php @@ -2,8 +2,7 @@ namespace App\Models; -use Cron\CronExpression; -use Carbon\CarbonImmutable; +use App\Helpers\Utilities; use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\Relations\BelongsTo; @@ -112,13 +111,9 @@ class Schedule extends Model * * @throws \Exception */ - public function getNextRunDate(): CarbonImmutable + public function getNextRunDate(): string { - $formatted = sprintf('%s %s %s %s %s', $this->cron_minute, $this->cron_hour, $this->cron_day_of_month, $this->cron_month, $this->cron_day_of_week); - - return CarbonImmutable::createFromTimestamp( - (new CronExpression($formatted))->getNextRunDate()->getTimestamp() - ); + return Utilities::getScheduleNextRunDate($this->cron_minute, $this->cron_hour, $this->cron_day_of_month, $this->cron_month, $this->cron_day_of_week)->toDateTimeString(); } /**