model = $model; } public function showJobs(): LengthAwarePaginator { $currentPage = LengthAwarePaginator::resolveCurrentPage(); $sanitizedPage = $currentPage - 1; $offsetRows = $this->perPage * $sanitizedPage; $total = $this->model->count(); $data = $this->model ->skip($offsetRows) ->take($this->perPage) ->get(); return new LengthAwarePaginator( $this->getOutput($data), $total, $this->perPage ); } public function getRedispatchableJobsInQueue(string $queue = null, array $columns = ['*']): collection { $failedJobs = $this->newQuery()->select($columns); if ($queue) { $failedJobs = $failedJobs->queuedAt($queue); } return $failedJobs->where( fn ($query) => $query ->whereNotNull('payload') ->whereRaw("payload <> ''") )->get(); } public function redispatchToQueue(string $queue = null, array $failedIds = []): int { $failedJobs = $this->newQuery(); if ($queue) { $failedJobs = $failedJobs->queuedAt($queue); } if (!empty($failedIds)) { $failedJobs = $failedJobs->whereIn('id', $failedIds); } $failedJobs = $failedJobs->get(); DB::beginTransaction(); $failedJobs->each(fn ($failedJob) => Repo::job()->add([ 'queue' => $failedJob->queue, 'payload' => $failedJob->payload, 'attempts' => 0, 'available_at' => Carbon::now()->timestamp, 'created_at' => Carbon::now()->timestamp, ])); DB::commit(); return $failedJobs->toQuery()->delete(); } protected function getOutput(Collection $data) { if ($this->outputFormat === self::OUTPUT_CLI) { return CLIFailedJobResource::collection($data); } return HttpFailedJobResource::collection($data); } }