0

I'm trying to get the ID or UUID of a failed job by calling depending on the failed() method on the Job class but I'm getting an error about the job being null

Here's my code:

public function failed(Throwable $exception)
    {
        $uuid = $this->job->uuid();
        $id = $this->job->getJobId();
        info("Job UUID: {$uuid}");
        info("Job ID: {$id}");
        $this->rescheduleImport();
    }

I'm trying to understand why this happens and an alternative way to go about this.

Willower
  • 1,099
  • 8
  • 22
  • The job ID is just a temporary identifier, it's not useful once the job has been run. The exception and the job object together should contain any information you need to identify the problem. – miken32 Aug 16 '22 at 23:21
  • @miken32 do you mean I cannot use this ID (or UUID) to manually rerun the job some time after it has failed? Also the job object is null within the failed method, so I'm unable to get it's uuid in there. – Willower Aug 17 '22 at 08:06
  • UUID might work, but the ID is just the primary key on the jobs table. It's gone once the job is run. My `failed()` method just fires an event which is passed both the `Exception` and the `Job`. I don't have the same issue. `public function failed(Throwable $exception): void {event(new JobFailed($this, $exception));}` – miken32 Aug 17 '22 at 13:40

0 Answers0