Queue | laravel-health-rust | Spatie       

 SPATIE  

laravel-health-rust
===================

spatie.be/open-source

  [Docs](https://spatie.be/docs)  [Laravel-health-rust](https://spatie.be/docs/laravel-health-rust/v1)  Available-checks  Queue

 Version   v1      

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

  Queue    
- [ Introduction ](https://spatie.be/docs/laravel-health-rust/v1/introduction)
- [ Support us ](https://spatie.be/docs/laravel-health-rust/v1/support-us)
- [ Requirements ](https://spatie.be/docs/laravel-health-rust/v1/requirements)
- [ Installation &amp; setup ](https://spatie.be/docs/laravel-health-rust/v1/installation-setup)
- [ Questions and issues ](https://spatie.be/docs/laravel-health-rust/v1/questions-issues)
- [ Changelog ](https://spatie.be/docs/laravel-health-rust/v1/changelog)
- [ Testing ](https://spatie.be/docs/laravel-health-rust/v1/testing)
- [ About us ](https://spatie.be/docs/laravel-health-rust/v1/about-us)

Usage
-----

- [ Registering your first check ](https://spatie.be/docs/laravel-health-rust/v1/basic-usage/registering-your-first-check)
- [ Creating custom checks ](https://spatie.be/docs/laravel-health-rust/v1/basic-usage/creating-custom-checks)
- [ Manually running checks ](https://spatie.be/docs/laravel-health-rust/v1/basic-usage/manually-running-checks)
- [ Conditionally running or modifying checks ](https://spatie.be/docs/laravel-health-rust/v1/basic-usage/conditionally-running-or-modifying-checks)
- [ Endpoints ](https://spatie.be/docs/laravel-health-rust/v1/basic-usage/endpoints)
- [ Pausing and resuming checks ](https://spatie.be/docs/laravel-health-rust/v1/basic-usage/pausing-and-resuming-checks)
- [ Registering the same check multiple times ](https://spatie.be/docs/laravel-health-rust/v1/basic-usage/registering-the-same-check-multiple-times)
- [ Testing ](https://spatie.be/docs/laravel-health-rust/v1/basic-usage/testing)

Storing results
---------------

- [ General ](https://spatie.be/docs/laravel-health-rust/v1/storing-results/general)
- [ As JSON ](https://spatie.be/docs/laravel-health-rust/v1/storing-results/in-a-json-file)
- [ In the cache ](https://spatie.be/docs/laravel-health-rust/v1/storing-results/in-cache)
- [ In the database ](https://spatie.be/docs/laravel-health-rust/v1/storing-results/in-the-database)
- [ Not storing results ](https://spatie.be/docs/laravel-health-rust/v1/storing-results/not-storing-results)

Configuring notifications
-------------------------

- [ General ](https://spatie.be/docs/laravel-health-rust/v1/configuring-notifications/general)
- [ Via mail ](https://spatie.be/docs/laravel-health-rust/v1/configuring-notifications/via-mail)
- [ Via Slack ](https://spatie.be/docs/laravel-health-rust/v1/configuring-notifications/via-slack)
- [ Via Microsoft Teams ](https://spatie.be/docs/laravel-health-rust/v1/configuring-notifications/via-teams)
- [ Via Oh Dear ](https://spatie.be/docs/laravel-health-rust/v1/configuring-notifications/via-oh-dear)

Viewing check results
---------------------

- [ General ](https://spatie.be/docs/laravel-health-rust/v1/viewing-results/general)
- [ On a webpage ](https://spatie.be/docs/laravel-health-rust/v1/viewing-results/on-a-webpage)
- [ On the CLI ](https://spatie.be/docs/laravel-health-rust/v1/viewing-results/on-the-cli)
- [ As JSON ](https://spatie.be/docs/laravel-health-rust/v1/viewing-results/as-json)

Available checks
----------------

- [ Overview ](https://spatie.be/docs/laravel-health-rust/v1/available-checks/overview)
- [ Backups ](https://spatie.be/docs/laravel-health-rust/v1/available-checks/backups)
- [ Application Cache ](https://spatie.be/docs/laravel-health-rust/v1/available-checks/cache)
- [ Cached config, routes, and events ](https://spatie.be/docs/laravel-health-rust/v1/available-checks/cached-config-routes-and-events)
- [ CPU load ](https://spatie.be/docs/laravel-health-rust/v1/available-checks/cpu-load)
- [ DB connection ](https://spatie.be/docs/laravel-health-rust/v1/available-checks/db-connection)
- [ DB connection count ](https://spatie.be/docs/laravel-health-rust/v1/available-checks/db-connection-count)
- [ DB size ](https://spatie.be/docs/laravel-health-rust/v1/available-checks/db-size-check)
- [ DB table size ](https://spatie.be/docs/laravel-health-rust/v1/available-checks/db-table-size-check)
- [ Debug mode ](https://spatie.be/docs/laravel-health-rust/v1/available-checks/debug-mode)
- [ Environment ](https://spatie.be/docs/laravel-health-rust/v1/available-checks/environment)
- [ Flare error count ](https://spatie.be/docs/laravel-health-rust/v1/available-checks/flare-error-count)
- [ Horizon ](https://spatie.be/docs/laravel-health-rust/v1/available-checks/horizon)
- [ Meilisearch ](https://spatie.be/docs/laravel-health-rust/v1/available-checks/meilisearch)
- [ Ping ](https://spatie.be/docs/laravel-health-rust/v1/available-checks/ping)
- [ Queue ](https://spatie.be/docs/laravel-health-rust/v1/available-checks/queue)
- [ Redis ](https://spatie.be/docs/laravel-health-rust/v1/available-checks/redis)
- [ Redis memory usage ](https://spatie.be/docs/laravel-health-rust/v1/available-checks/redis-memory-usage)
- [ Reverb ](https://spatie.be/docs/laravel-health-rust/v1/available-checks/reverb)
- [ Schedule ](https://spatie.be/docs/laravel-health-rust/v1/available-checks/schedule)
- [ Security advisories ](https://spatie.be/docs/laravel-health-rust/v1/available-checks/security-advisories)
- [ Used disk space ](https://spatie.be/docs/laravel-health-rust/v1/available-checks/used-disk-space)

Security
--------

- [ Using Secret Token ](https://spatie.be/docs/laravel-health-rust/v1/security/using-secret-token)

 Queue
=====

###  On this page 

1. [ Usage ](#content-usage)

This check will make sure that queued jobs are running. This check works by dispatching a test job (this will be done via a scheduled command), and verifying if that test job is handled on time.

This check relies on cache.

Usage
-----------------------------------------------------------------------

First, schedule `health:queue-check-heartbeat` every minute. This command dispatches a small job on each queue you monitor. `health:queue-check` remains a command alias.

### Scheduling the command

`integration::register_schedule` registers the queue heartbeat command alongside the health runner and scheduler heartbeat. Jobs use Laravel's configured queue connection.

```
use spatie_health::integration::register_schedule;

register_schedule(&mut scheduler);
```

### Handling the heartbeat job

Run Laravel's `queue:work` with the queues you monitor. Laravel registers `HeartbeatJob` through its job macro, then restores, executes and acknowledges it. A heartbeat is written by its handler. Use an asynchronous connection such as `QUEUE_CONNECTION=database`; a synchronous connection executes inline and cannot prove a worker is alive. A database queue needs Laravel's queue tables. Configure a shared Laravel cache for separate scheduler and worker processes.

Register a `QueueCheck`. With no explicit queues, it monitors the default connection's configured queue name. It fails if the job dispatched by `health:queue-check-heartbeat` isn't handled within 5 minutes. Duplicate queue names dispatch only one heartbeat.

```
use spatie_health::{Check, Health, checks::QueueCheck};

let mut health = Health::new();
health.checks([QueueCheck::new().registered()])?;
```

You can monitor a different queue by setting `queues`.

```
use spatie_health::{Check, Health, checks::QueueCheck};

let mut check = QueueCheck::new();
check.queues = vec!["email".into()];

let mut health = Health::new();
health.checks([check.registered()])?;
```

The `queues` field can accept multiple queues.

```
use spatie_health::{Check, Health, checks::QueueCheck};

let mut check = QueueCheck::new();
check.queues = vec!["email".into(), "payment".into()];

let mut health = Health::new();
health.checks([check.registered()])?;
```

### Customizing job time

By default, `QueueCheck` fails when its heartbeat job isn't handled within 5 minutes. Customize that time using `maximum_age`.

```
use spatie_health::checks::QueueCheck;

let mut check = QueueCheck::new();
check.maximum_age = std::time::Duration::from_secs(10 * 60);
```

### Customize the cache store

Set `QueueCheck::cache_store` to a named Laravel cache store. Both the dispatched job and the reader use it. Use shared database or Redis cache across scheduler, worker and HTTP processes.

### Customizing the job and connection

Override the native `HeartbeatDispatcher` container service in `.with_services(...)` to choose dispatch options:

```
use spatie_health::integration::HeartbeatDispatcher;

let dispatcher = HeartbeatDispatcher::using(|heartbeat| {
    heartbeat.dispatch().on_connection("database")
});
```

Register it with `services.instance(dispatcher)`. To use a different job, return your own native job's `PendingDispatch` from this closure. The dispatcher applies each monitored queue after the closure, while preserving your selected connection and native job options. Define attempts and timeouts with `#[laravel::queue::job]`. Its handler can call `heartbeat.record().await` to write to the selected cache. The [native job test](https://github.com/spatie/laravel-health-rust/blob/main/tests/framework.rs) demonstrates a custom job, seven attempts, an eleven-second timeout and a custom connection.

 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)
