mercredi 25 octobre 2017

Send response but keep long running script going to prevent timeout?

I am wondering how to deal with this. I have a webhook endpoint which responds to a webhook call from Github.

It starts a long running process in where it clones the repository from which the webhook call was made.

/**
* The webhook endpoint.
*
* @param Request $request
* @return mixed
* @throws \Exception
*/
public function webhook(Request $request)
{
    // The type of GitHub event that we receive.
    $event = $request->header('X-GitHub-Event');

    $url = $this->createCloneUrl();
    $this->cloneGitRepo($url);

    return new Response('Webhook received succesfully', 200);
}

The problem with this is that Github gives an error when the response is not provided soon enough.

We couldn’t deliver this payload: Service Timeout

This is rightfully so because my cloneGitRepo method is simply blocking the execution of the response and it is taking too long.

How can I still deliver a response to acknowledge to Github that the webhook call has been made successfully and start my long running process?

I am using Laravel for all of this with Redis, maybe something can be accomplished there? I am open to all suggestions.



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2ixvgcH
via IFTTT

Aucun commentaire:

Enregistrer un commentaire