Customization | 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)  Customization

 Version   v1      

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

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

 Customization
=============

###  On this page 

1. [ Providers and configuration ](#content-providers-and-configuration)
2. [ Native jobs ](#content-native-jobs)
3. [ Task and log models ](#content-task-and-log-models)

Providers and configuration
-----------------------------------------------------------------------------------------------------------------------------------------

- Install with `monitor.install(builder)` or `providers.add(service_provider(monitor))`, not both.
- The package-tools provider registers services, console commands and scheduler listeners.
- Application configuration and service bindings run after provider defaults. They can replace typed settings and the `ScheduleMonitor` or `OhDear` instances.

```
use laravel::{Application, config::Env};
use spatie_schedule_monitor::{Config, MonitoredTask, ScheduleMonitor, service_provider};

let monitor = ScheduleMonitor::new([MonitoredTask::new("cleanup", "0 2 * * *")?])?;
let app = Application::configure()
    .replace_env(Env::default())
    .with_providers(move |providers| {
        providers.add(service_provider(monitor));
    })
    .with_config(|config, _| {
        config.set(Config {
            retention_days: 7,
            ping_queue: Some("monitoring".into()),
            ..Default::default()
        });
    })
    .create();
```

- `Config` also controls `ping_attempts`, `retry_delay` and `ping_lifetime`.
- Its queue name selects dispatch placement, not a connection. Configure the application's queue connection and start its worker separately.
- Keep task names, cron expressions, timezones and grace periods in task definitions.

Native jobs
-----------------------------------------------------------------------------------------

- Use `.queue_pings()` for the built-in job, or `.ping_job(factory)` for your own native job.
- Configure job options, middleware and injected services through the framework.
- Each job receives one persisted log identifier, not the entire outbox.

```
use laravel::{container::Inject, queue::Queueable};
use spatie_schedule_monitor::{MonitoredTask, OhDear, ScheduleMonitor};

#[derive(Clone, Debug, Queueable)]
struct PingMonitor { log_id: i64 }

#[laravel::queue::job(name = "app.ping-monitor", tries = 5, backoff = 30.seconds())]
impl PingMonitor {
    async fn handle(self, client: Inject<OhDear>, monitor: Inject<ScheduleMonitor>) -> laravel::Result<()> {
        client.ping(&monitor, self.log_id).await?;
        Ok(())
    }
}

let monitor = ScheduleMonitor::new([MonitoredTask::new("cleanup", "0 2 * * *")?])?
    .ping_job(|log_id| PingMonitor { log_id });
```

- Bind the HTTP client and configure a non-sync queue before enabling delivery.
- A queue name in `Config` overrides the job type's default queue. Retry and timeout options still belong to the job.
- Neither provider registration nor this example dispatches a job or contacts a monitor.

Task and log models
-----------------------------------------------------------------------------------------------------------------

- Select an application-owned `MonitorStore` with `.store(application_store)` before cloning or installation. All persistence operations use this contract, including outbox reads and acknowledgements.
- Default trait methods use the same implementation as `DatabaseStore`, with framework queries, transactions and configured table names. Bulk queries do not run ORM hooks.
- Override `record` to create your log model and update task health in one transaction. Return the log identifier for queued delivery. Use native `#[model(hooks)]`, `Draft`, `Changes`, model connections and mapped columns as needed.
- Preserve success, failure, start and skip semantics. A new start or skip must not erase a failure or advance the last successful completion.
- See the [executed custom-model example](https://github.com/spatie/laravel-schedule-monitor-rust/blob/main/tests/scheduler.rs). It maps the epoch-millisecond column with `#[column("created_at")] event_at: i64` to avoid automatic timestamp handling.
- When replacing tables, connections or query scopes, implement the corresponding reads, sync, pruning and outbox methods together. `.table_names(...)` configures the default store, not arbitrary application models.
- Use `monitor.definitions()` in a custom sync implementation to read the registered definitions.

 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)
