Monitoring and Oh Dear | laravel-schedule-monitor-rust | Spatie       

 SPATIE  

laravel-schedule-monitor-rust
=============================

spatie.be/open-source

  [Docs](https://spatie.be/docs)  [Laravel-schedule-monitor-rust](https://spatie.be/docs/laravel-schedule-monitor-rust/v1)  Monitoring and Oh Dear

 Version   v1      

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

  Monitoring and Oh Dear    
- [ Introduction ](https://spatie.be/docs/laravel-schedule-monitor-rust/v1/introduction)
- [ Support us ](https://spatie.be/docs/laravel-schedule-monitor-rust/v1/support-us)
- [ Installation ](https://spatie.be/docs/laravel-schedule-monitor-rust/v1/installation-and-setup)
- [ Usage ](https://spatie.be/docs/laravel-schedule-monitor-rust/v1/usage)
- [ Monitoring and Oh Dear ](https://spatie.be/docs/laravel-schedule-monitor-rust/v1/monitoring)
- [ Testing ](https://spatie.be/docs/laravel-schedule-monitor-rust/v1/testing)
- [ Changelog ](https://spatie.be/docs/laravel-schedule-monitor-rust/v1/changelog)
- [ Customization ](https://spatie.be/docs/laravel-schedule-monitor-rust/v1/customization)
- [ Registering application commands ](https://spatie.be/docs/laravel-schedule-monitor-rust/v1/scheduled-commands)

 Monitoring and Oh Dear
======================

###  On this page 

1. [ Completion deadlines ](#content-completion-deadlines)
2. [ Oh Dear ](#content-oh-dear)
3. [ Errors ](#content-errors)
4. [ Queued delivery ](#content-queued-delivery)

Completion deadlines
--------------------------------------------------------------------------------------------------------------------

- Monitoring begins at the UTC minute of first sync. Later syncs preserve that baseline and health history.
- A task becomes late strictly after its first expected completion plus grace. Missing another period does not reset the deadline.
- A success advances the expected run to the next occurrence. Failure stays failed until a later success, even if another run starts. The last persisted terminal event breaks timestamp ties.
- Use `statuses(timestamp)` for an explicit instant. `schedule-monitor:verify` uses the application clock.
- Failed executions produce one failed terminal log, even though the native scheduler emits both finished and failed events. Constraint or lock failures may have no starting event.
- Skipped runs do not satisfy completion deadlines. Non-UTC carrier minutes outside the local cron produce no monitor logs or expected completions. See [timezones](usage#timezones).
- `schedule-monitor:prune --days 30` keeps the exact 30-day boundary, health timestamps and pending pings. After a long consumer outage, expire pending entries through the outbox consumer before pruning.

Oh Dear
-----------------------------------------------------------------------------

`monitor.cron_checks()` returns the remote registration payload without making a request. A weekly crawl can keep its 45-minute grace:

```
use spatie_schedule_monitor::{MonitoredTask, ScheduleMonitor};

let monitor = ScheduleMonitor::new([
    MonitoredTask::new("search-crawl", "0 2 * * 1")?
        .timezone("Europe/Brussels")?
        .grace_minutes(45),
])?;
let checks = monitor.cron_checks();
assert_eq!(checks[0].grace_time_in_minutes, 45);
assert_eq!(checks[0].server_timezone, "Europe/Brussels");
```

1. Construct `OhDear::new(api_url, token)?` using secrets from the application environment. It uses the native HTTP client with a ten-second timeout, no redirects and no transport retries. Framework HTTP fakes apply.
2. Bind it with `.oh_dear(client)` before installing the monitor, or bind `OhDear` in the native container.
3. Run local sync before binding ping URLs or provisioning remote checks.
4. Bind an authorized URL with `monitor.set_ping_url(name, Some(url)).await?`, or provision checks through an explicitly authorized API operation.

- `client.sync(monitor_id, &monitor).await?` replaces remote checks and saves returned ping URLs. **It may delete remote checks and requires authorization for that monitor.**
- `client.register_missing(monitor_id, &monitor).await?` creates checks without a persisted local registration time, without replacing remote entries. It saves each binding before continuing. Remote writes are not automatically retried; a later local storage failure can require manual reconciliation.
- `client.verify(monitor_id).await?` checks credentials and connectivity with a GET.
- Console equivalents are `schedule-monitor:sync --oh-dear <id> [--keep-old]` and `schedule-monitor:verify --oh-dear <id>`. Without `--oh-dear`, both stay local.
- `client.ping_endpoint(url)?` selects a custom ping root. Sync appends each returned check UUID. Ping requests never include the API token.
- `monitor.set_ping_url(name, None).await?` disables delivery and clears pending pings for a task.
- `.monitor_at_oh_dear(false)` keeps local health and history but excludes remote registration. Local sync clears old URLs and pending pings for excluded tasks.

Errors
--------------------------------------------------------------------------

- `OhDear::new` and `ping_endpoint` return `Result<_, OhDearError>`. Invalid URLs never appear in the error text.
- Async operations return `laravel::Result`. Use `error.downcast_ref::<OhDearError>()` or `error.downcast_ref::<RegistrationError>()` to distinguish failures without parsing messages.
- `NotSynchronized` means local sync is required. `UnknownTask` means the name is absent from the registry. `RemoteMonitoringDisabled` means a local-only task cannot bind a ping URL.
- `MissingToken` and `MissingMonitorId` identify missing API configuration. Empty tokens remain valid for ping-only delivery.
- `InvalidResponse` covers malformed JSON, unexpected or duplicate check names, missing checks and invalid UUIDs.

Queued delivery
-----------------------------------------------------------------------------------------------------

- Listeners persist pending pings atomically with event logs. Installation does not enable delivery.
- Use `.queue_pings()` for one native `PingOhDearJob` per pending entry, or `.ping_job(factory)` for your job. Configure a non-sync queue and run its worker; sync queues deliver inline. See [customization](customization).
- Alternatively, run `client.flush_pings(&monitor, limit).await?` in an application-context command. Entries are oldest first. Do not flush manually alongside queued delivery.
- Delivery is at-least-once. A crash after HTTP success but before acknowledgement can resend a ping. Dispatch failure leaves the durable entry available for recovery.
- Each pass defaults to three HTTP attempts with ten seconds between attempts. `Config` controls attempts, delay and the ten-minute event lifetime. Older entries expire without HTTP requests; retries do not renew their lifetime.
- Failed passes return an error, retain the entry and dispatch `OhDearPingFailed` with the log, attempt count and status. The default queue job also allows three attempts with ten-second backoff; replace the job to change queue options.
- `client.ping(&monitor, log_id).await?` delivers one entry and ignores missing or acknowledged entries.
- Finished pings include runtime seconds and exit code. Enable `.send_starting_ping(true)` to send starts and omit runtime from finished pings, allowing the service to measure elapsed time.
- Failed pings include the native failure message. Output stays local; memory is not measured. `tasks()` exposes registration and last successful ping timestamps.
- Errors and client Debug output omit URLs, tokens and response bodies. Framework tracing and application logs still need access controls. Protect stored failures and output, and use only trusted ping endpoints.
- Local HTTP tests cover provisioning, payloads, retries and expiry. They do not validate live credentials, production connectivity or service-side behavior.

 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)
