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

 SPATIE  

laravel-webhook-server-rust
===========================

spatie.be/open-source

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

 Version   v1      

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

  Retrying failed webhooks    
- [ Introduction ](https://spatie.be/docs/laravel-webhook-server-rust/v1/introduction)
- [ Installation and setup ](https://spatie.be/docs/laravel-webhook-server-rust/v1/installation-and-setup)
- [ Sending webhooks ](https://spatie.be/docs/laravel-webhook-server-rust/v1/sending-webhooks)
- [ Signing requests ](https://spatie.be/docs/laravel-webhook-server-rust/v1/signing-requests)
- [ Retrying failed webhooks ](https://spatie.be/docs/laravel-webhook-server-rust/v1/retrying-failed-webhooks)
- [ Transport options ](https://spatie.be/docs/laravel-webhook-server-rust/v1/transport-options)
- [ Events ](https://spatie.be/docs/laravel-webhook-server-rust/v1/events)
- [ Testing webhooks ](https://spatie.be/docs/laravel-webhook-server-rust/v1/testing-webhooks)
- [ Upgrading ](https://spatie.be/docs/laravel-webhook-server-rust/v1/upgrading)
- [ Testing ](https://spatie.be/docs/laravel-webhook-server-rust/v1/testing)
- [ Changelog ](https://spatie.be/docs/laravel-webhook-server-rust/v1/changelog)
- [ Support us ](https://spatie.be/docs/laravel-webhook-server-rust/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 response outside 2xx, a connection failure or a timeout fails the attempt. Redirects are not followed by default. Three attempts are allowed, with delays of 10 and 100 seconds. With more attempts, exponential backoff grows through 1,000 and 10,000 to a maximum of 100,000 seconds.

Set `Config.tries` and `Config.timeout`, or call `maximum_tries(5)` and `timeout(Duration::from_secs(5))`. Zero attempts and zero timeout are rejected before dispatch.

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

Use `retry_on(Some(vec![408, 425, 429, 500, 502, 503, 504]))` to restrict HTTP retries. `retry_on(None)` restores retrying all non-2xx statuses; `Some(vec![])` disables status retries but not connection-failure retries.

`respect_retry_after(true)` reads non-negative seconds or an HTTP date as a minimum delay. Invalid values are ignored and past dates add no delay. `with_jitter(true)` randomizes the strategy's delay from zero through its whole-second delay, inclusive. Retry-After applies after jitter and never shortens it.

These options default to false and also have corresponding `Config` fields. Queue drivers impose delay and payload limits. Ensure your configured strategy and the receiver's requested delay fit your driver.

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

```
use std::{sync::Arc, time::Duration};
use spatie_laravel_webhook_server::{BackoffStrategy, Config};

#[derive(Debug)]
struct LinearBackoff;

impl BackoffStrategy for LinearBackoff {
    fn wait_after_attempt(&self, attempt: u32) -> Duration {
        Duration::from_secs(u64::from(attempt) * 15)
    }
}

let mut config = Config::default();
config.backoff_strategies.insert("linear".into(), Arc::new(LinearBackoff));
config.backoff_strategy = "linear".into();
assert_eq!(config.backoff_strategies["linear"].wait_after_attempt(2), Duration::from_secs(30));
```

Register the same name on every worker. Select it per call with `use_backoff_strategy("linear")`. Unknown names fail preparation, or fail the worker if its configuration no longer contains the name.

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

Retries release the native Laravel job with a delay. They are not HTTP-client retry loops. Synchronous delivery and the `sync` queue connection make one attempt only and emit final-failure events immediately when it fails.

By default, a final delivery failure emits both failed and final-failed events and deletes the delivery job. Enable `throw_exception_on_failure(true)` to mark the queue job failed and return an error synchronously. Event-listener errors propagate independently of this setting.

The package enforces per-call attempt limits inside its handler; configure worker hard timeouts above the HTTP timeout. A process killed before the handler can finish cannot emit a result event. Queue storage/worker failures remain Laravel's responsibility.

 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)
