Retrying failed webhooks | laravel-webhook-server-go | Spatie       

 SPATIE  

laravel-webhook-server-go
=========================

spatie.be/open-source

  [Docs](https://spatie.be/docs)  [Laravel-webhook-server-go](https://spatie.be/docs/laravel-webhook-server-go/v1)  Retrying failed webhooks

 Version   v1      

 Other versions for crawler [v1](https://spatie.be/docs/laravel-webhook-server-go/v1) 

  Retrying failed webhooks    
- [ Introduction ](https://spatie.be/docs/laravel-webhook-server-go/v1/introduction)
- [ Installation and setup ](https://spatie.be/docs/laravel-webhook-server-go/v1/installation-and-setup)
- [ Sending webhooks ](https://spatie.be/docs/laravel-webhook-server-go/v1/sending-webhooks)
- [ Signing requests ](https://spatie.be/docs/laravel-webhook-server-go/v1/signing-requests)
- [ Retrying failed webhooks ](https://spatie.be/docs/laravel-webhook-server-go/v1/retrying-failed-webhooks)
- [ Transport options ](https://spatie.be/docs/laravel-webhook-server-go/v1/transport-options)
- [ Events ](https://spatie.be/docs/laravel-webhook-server-go/v1/events)
- [ Testing webhooks ](https://spatie.be/docs/laravel-webhook-server-go/v1/testing-webhooks)
- [ Differences from PHP ](https://spatie.be/docs/laravel-webhook-server-go/v1/upgrading)
- [ Testing ](https://spatie.be/docs/laravel-webhook-server-go/v1/testing)
- [ Releasing ](https://spatie.be/docs/laravel-webhook-server-go/v1/releasing)
- [ Changelog ](https://spatie.be/docs/laravel-webhook-server-go/v1/changelog)
- [ Support us ](https://spatie.be/docs/laravel-webhook-server-go/v1/support-us)

 Retrying failed webhooks
========================

###  On this page 

1. [ Response-aware retries ](#content-response-aware-retries)
2. [ Custom backoff strategies ](#content-custom-backoff-strategies)
3. [ Queue limits and final failures ](#content-queue-limits-and-final-failures)

A final response outside `2xx`, a connection failure, or a request exceeding the timeout fails the attempt. Redirects follow Go's default policy of up to ten redirects. A final `3xx` response fails too. No cookie jar is used.

By default, the package makes three attempts in total. It waits 10 seconds before the second and 100 seconds before the third. Exponential backoff then grows to 1,000 seconds and beyond when you configure more attempts, capped at 100,000 seconds.

Set `cfg.Tries` and `cfg.Timeout` globally, or change `o.Tries` and `o.Timeout` using `call.Configure`. Timeouts are Go `time.Duration` values and must be positive.

Response-aware retries
--------------------------------------------------------------------------------------------------------------------------

The default policy retries every unsuccessful HTTP status. Limit retries, honor the receiver's minimum delay, and add full jitter with:

```
id, err := webhookserver.From(ctx).Call("https://other-app.com/webhooks").
    Payload(map[string]string{"key": "value"}).Secret("your-shared-secret").
    Configure(func(o *webhookserver.Options) {
        o.RetryableStatuses = []int{408, 425, 429, 500, 502, 503, 504}
        o.RespectRetryAfter = true
        o.Jitter = true
    }).Dispatch(ctx)
```

- A nil `RetryableStatuses` retries all unsuccessful statuses.
- `[]int{}` disables HTTP-status retries. Connection failures still retry.
- An excluded status immediately fires both failure events and honors `ThrowOnFailure`.
- `RespectRetryAfter` accepts non-negative seconds or an HTTP date. Invalid or unrepresentable values are ignored. Past dates add no delay. The header never shortens backoff.
- `Jitter` chooses a random duration from zero through the strategy delay, inclusive. `Retry-After` is applied afterwards as a minimum.

All three settings are opt-in and configurable globally or per call.

Custom backoff strategies
-----------------------------------------------------------------------------------------------------------------------------------

Register a named function taking the attempt number and returning a non-negative `time.Duration`:

```
webhookserver.New(func(cfg *webhookserver.Config) {
    cfg.Backoffs["custom"] = func(attempt int) time.Duration {
        return time.Duration(attempt * 17) * time.Second
    }
    cfg.Backoff = "custom"
})
```

Select another registered strategy per call using `o.Backoff`. Register strategies on every worker. Functions do not enter serialized jobs. A missing worker strategy or negative delay fails the job.

Queue limits and final failures
-----------------------------------------------------------------------------------------------------------------------------------------------------

Retries use delayed queue jobs, not immediate HTTP-client retries. Synchronous calls do not wait or loop. Make sure the resulting delay, including `Retry-After`, fits your queue driver's limits. Amazon SQS permits at most 15 minutes.

Listen to [webhook events](events) to record failures. Set `ThrowOnFailure = true` to mark the queue job as failed and return its error on final failure. The default deletes the final failed delivery after firing its events.

`Config.ShouldStop(ctx, result)` can stop retries based on application state. This replaces the PHP job's `shouldBeRemovedFromQueue` hook. Replace the job itself when you need different handling or failure cleanup.

 A good
match?
-------------

### What we do best

- All things Laravel
- Custom frontend components
- Building APIs
- AI-powered features
- Simplifying things
- Clean solutions
- Integrating services

### Not our cup of tea

- WordPress themes
- Cutting corners
- Free mockups to win a job
- "Just execute the briefing"

 In short: we'd like to be a **substantial part** of your project.

 [ Get in touch via email ](mailto:info@spatie.be?subject=A%20good%20match%21&body=Tell%20us%20as%20much%20as%20you%20can%20about%0A-%20your%20online%20project%0A-%20your%20planning%0A-%20your%20budget%0A-%20%E2%80%A6%0A%0AAnything%20that%20helps%20us%20to%20start%20straightforward%21)
