Schedule | 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  Schedule

 Version   v1      

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

  Schedule    
- [ 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)

 Schedule
========

###  On this page 

1. [ Usage ](#content-usage)
2. [ Ping Configuration ](#content-ping-configuration)

This check will make sure the schedule is running. If the check detects that the schedule is not run every minute, it will fail.

This check relies on cache.

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

First, you must register the `ScheduleCheck`.

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

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

Next, you must schedule `health:schedule-check-heartbeat` to run every minute. We recommend putting this command as the very last command in your schedule.

### Scheduling the heartbeat

`integration::register_schedule` registers this command alongside the health runner and queue heartbeat. Your scheduler must execute the registered commands.

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

register_schedule(&mut scheduler);
```

### Running the scheduler

Run Laravel's `schedule:run` once per minute or use `schedule:work`. The package no longer owns a scheduler loop. See [installation](../installation-setup) for registration.

### Customize the cache store

Set `ScheduleCheck::cache_store` to a named Laravel store. Both the heartbeat command and the check use that selection. Use a shared database or Redis cache across processes. You can set `cache_key` to give this application its own heartbeat key.

### Customizing the maximum heart beat age

The `health:schedule-check-heartbeat` command will write the current timestamp into the cache. The `ScheduleCheck` will verify that that timestamp is not over a minute old.

Should you get too many false positives, you can change the max age of the timestamp by setting `heartbeat_max_age`.

```
use spatie_health::checks::ScheduleCheck;

let mut check = ScheduleCheck::new();
check.heartbeat_max_age = std::time::Duration::from_secs(2 * 60);
```

### Checking individual scheduled tasks

This check monitors the scheduler as a whole. To monitor an individual task, record its completion time and verify it in [a custom check](../basic-usage/creating-custom-checks).

Ping Configuration
--------------------------------------------------------------------------------------------------------------

The check can be configured to ping a URL when the scheduler is running successfully. This is useful for external monitoring services like Oh Dear, Pingdom, Envoyer heartbeats etc.

If a URL is configured, it will automatically be pinged each time the health checks run at the frequency you've configured. The URL will only be pinged if the check passes.

The ping is independent of the check's status, so the check may pass but the ping may fail (e.g. the ping URL is malformed or unreachable).

### Simple Setup

The easiest way to set up pinging is through your `.env` file:

```
SCHEDULE_HEARTBEAT_URL=https://your-monitoring-service.com/ping/abc123
```

The provider reads this variable into `HealthConfig`. A check-specific URL overrides it:

```
use spatie_health::checks::ScheduleCheck;

let mut check = ScheduleCheck::new();
check.heartbeat_url = std::env::var("SCHEDULE_HEARTBEAT_URL").ok();
```

### Advanced Configuration

For more control, you can set the timeout and retry times in your check registration. The defaults are 3 seconds and 1 attempt.

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

let mut check = ScheduleCheck::new();
check.ping_timeout = std::time::Duration::from_secs(5);
check.ping_retry_times = 3;

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

Read `heartbeat_delivered` in the result metadata to see whether delivery succeeded.

 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)
