Improve "first task" checks (#1926)

This commit is contained in:
Boy132 2025-11-24 00:48:32 +01:00 committed by GitHub
parent b1b723485f
commit 611b8649e0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 17 additions and 5 deletions

View File

@ -72,7 +72,7 @@ class TasksRelationManager extends RelationManager
->default('restart'),
TextInput::make('time_offset')
->label(trans('server/schedule.tasks.time_offset'))
->hidden(fn (Get $get) => config('queue.default') === 'sync' || $get('sequence_id') === 1 || $schedule->tasks->isEmpty())
->hidden(fn (Get $get, ?Task $task) => config('queue.default') === 'sync' || $schedule->tasks->isEmpty() || $task?->isFirst())
->default(0)
->numeric()
->minValue(0)
@ -108,8 +108,8 @@ class TasksRelationManager extends RelationManager
TextColumn::make('time_offset')
->label(trans('server/schedule.tasks.time_offset'))
->hidden(fn () => config('queue.default') === 'sync')
->suffix(fn (Task $task) => $task->sequence_id > 1 ? ' '. trans_choice('server/schedule.tasks.seconds', $task->time_offset) : null)
->state(fn (Task $task) => $task->sequence_id === 1 ? null : $task->time_offset)
->state(fn (Task $task) => $task->isFirst() ? null : $task->time_offset)
->suffix(fn ($state) => ' ' . trans_choice('server/schedule.tasks.seconds', $state))
->placeholder(trans('server/schedule.tasks.first_task')),
IconColumn::make('continue_on_failure')
->label(trans('server/schedule.tasks.continue_on_failure'))

View File

@ -142,4 +142,12 @@ class Schedule extends Model implements Validatable
{
return $this->belongsTo(Server::class);
}
public function firstTask(): ?Task
{
/** @var ?Task $task */
$task = $this->tasks()->orderBy('sequence_id')->first();
return $task;
}
}

View File

@ -120,4 +120,9 @@ class Task extends Model implements Validatable
'server_id' // schedules.server_id
);
}
public function isFirst(): bool
{
return $this->schedule->firstTask()?->id === $this->id;
}
}

View File

@ -21,8 +21,7 @@ class ProcessScheduleService
*/
public function handle(Schedule $schedule, bool $now = false): void
{
/** @var ?Task $task */
$task = $schedule->tasks()->orderBy('sequence_id')->first();
$task = $schedule->firstTask();
if (!$task) {
throw new DisplayException('Cannot process schedule for task execution: no tasks are registered.');