mercredi 17 avril 2019

Laravel 5.5 handling failed jobs

I am trying to figure out how to handle failed jobs. So in my Job class, I basically have something like this

public function handle()
{
    try {
        $someService = new SomeService($);
        $success = $someService->makeApiRequest();

        if($success) {
            //do something
        } else {
            //trigger failed
        }
    } catch (\Exception $e) {
        $this->failed($e);
    }
}

public function failed(Exception $exception)
{
    //Log information
}

What this is doing is calling a Service class which makes an API request. This class returns true or false based on whether the API call was successful or not.

At the moment, I just have the API method returning false. This should mean that the job has failed. However, the failed function is not called, and as far as Laravel is concerned, the job is processed.

How can I manually trigger the failed function seeing that I dont have an Exception?

Thanks



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire