Support the ongoing development of Laravel.io →
Architecture Queues Jobs
0

To catch the job ID in the failed function of a job, you can access it through the $this->job property. Here is an example:

use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;

class YourJob implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    public function __construct()
    {
        //
    }

    public function handle()
    {
        // Job logic
    }

    public function failed(\Exception $exception = null)
    {
        $jobId = $this->job->getJobId();

        // Perform actions with the job ID (e.g., sending a notification)
    }
}

By using $this->job->getJobId(), you can retrieve the job ID within the failed function of your job. This gives you the flexibility to perform specific actions or send notifications related to the failed job using its ID.

Last updated 1 year ago.

lechuhuuha liked this reply

1

Sign in to participate in this thread!

Eventy

Your banner here too?

Raj Bhatta rajmonto Joined 29 Jun 2023

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.