in some exception in laravel job i need retry until get 200 response code

72 Views Asked by At

hi i want try this job until get 200 response and staircase retry i mean first try after 1s second after 10s third after 40s and etc

postGateway is an external api and it is often busy and I get a timeout exception, I want to retry the job to get 200 and this api might be down for 2 or even 3 hours and I want to retry for a long time. I want to just try this again as I save the job status and show it to the users so if i dispatch job uuid change and i can't find this job , do u have any same experience and what is best practice of this

i do this two job but not work correctly : 1)i use released in failed function but released not infinite and failed job after tries 2)i put dispatch(new $this) in failed function but it's not correct.

i have one job class in laravel like this :

public function handle()
    {
        try {
            $gateway = new PostGateway();
            $gateway->ping();

        } catch (\Exception $e) {
            $this->failed($e);
        }
    }

    public function failed($e)
    {
            if ($e instanceof HttpClientException) {
                /* so what can I do here */
            }
   

        throw  $e;
    }
0

There are 0 best solutions below