Make sure schedules run with UTC (#657)

* make sure schedules use UTC for `next_run_at`

* use function from Utilities
This commit is contained in:
Boy132 2024-10-23 21:59:13 +02:00 committed by GitHub
parent 60792c05c2
commit c53ef78d89
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 5 additions and 11 deletions

View File

@ -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) {

View File

@ -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

View File

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