-
Notifications
You must be signed in to change notification settings - Fork 5
Description
Hello! Thank you for this awesome plugin!
I have written a simple rsync deployment script, and used your plugin successfully, but had to make one (possibly stupid) modification.
Here's how the deployment works.
A route is created to trigger a deployment
It returns a JSON response
'routes' => [
[
'pattern' => 'deploy-secret-url',
'method' => 'POST|GET',
'action' => function() {
return Response::json(array('status' => 'deployment in progress'));
}
],
],
A hook runs after the route
It uses rsync to deploy the website
'hooks' => [
'route:after' => function($route, $path, $method, $result) {
if ($path == "deploy-secret-url") {
// Simplified for brevity
$rsync->sync($origin, $target);
if ($rsync->getExitCode() == 0) {
$request = new Remote('example.com/webhook/deploy/success', array(
'method' => 'POST',
));
} else {
$request = new Remote('example.com/webhook/deploy/error', array(
'method' => 'POST',
));
}
}
}
]
The problem I was having is that these two things happen exactly at the same time in this order:
- the post request to the success route is sent
- the response to the original request is sent (in response to 'deploy-secret-url')
Because of this the field receives a "success" state and a "progress" state at the same time, but since the progress state comes just after the success state, the success state is overwritten, and the field never reaches the success state.
The way I fixed this was by adding this code to the setState function in WebhookField.php after line 100:
if ($status == 'progress' && time() - $cache->modified($hookName) < 1000) {
return 'progress status ignored';
}
Which ignores the progress state that travels right after/with the success state given the way this code is executing.
There's probably a far more elegant solution out there (would love to learn – I didn't want to introduce queueing or async curl requests) but thought I'd post this in case it is helpful for anyone.
Thanks again!