Installation and setup | laravel-schedule-monitor-go | Spatie       

 SPATIE  

laravel-schedule-monitor-go
===========================

spatie.be/open-source

  [Docs](https://spatie.be/docs)  [Laravel-schedule-monitor-go](https://spatie.be/docs/laravel-schedule-monitor-go/v1)  Installation and setup

 Version   v1      

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

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

 Installation and setup
======================

###  On this page 

1. [ Preparing the database ](#content-preparing-the-database)
2. [ Publishing the config file ](#content-publishing-the-config-file)
3. [ Debugging failed pings ](#content-debugging-failed-pings)
4. [ Cleaning the database ](#content-cleaning-the-database)
5. [ Syncing the schedule ](#content-syncing-the-schedule)

Requires Go 1.27 or newer and Laravel Go `go.laravel.com v0.1.0`.

```
go get github.com/spatie/laravel-schedule-monitor-go@v0.1.0
```

Install the package explicitly. Installing the Go module alone does not activate it:

```
import (
    laravel "go.laravel.com"
    "github.com/spatie/laravel-schedule-monitor-go"
)

func Options() laravel.Options {
    return laravel.Options{
        Packages: []laravel.Package{schedulemonitor.New()},
    }
}
```

Preparing the database
--------------------------------------------------------------------------------------------------------------------------

Register your application's database driver and set `DATABASE_URL`. Package registration adds two migrations for `monitored_scheduled_tasks` and `monitored_scheduled_task_log_items`. Run them with the application's migration command:

```
go run . migrate
```

Migrations are forward-only. For custom models or tables, set `cfg.Migrations = false` and register your own migrations. The schema is native to this Go port and is not an in-place upgrade of PHP or Rust tables.

Publishing the config file
--------------------------------------------------------------------------------------------------------------------------------------

There is no file to publish in a compiled Go application. Pass callbacks to `New` to change typed settings after environment defaults:

```
schedulemonitor.New(func(cfg *schedulemonitor.Config) {
    cfg.RetentionDays = 14
    cfg.DateFormat = "2006-01-02 15:04:05"
    cfg.Grace = 5 * time.Minute
    cfg.OhDear.Queue = "monitoring"
})
```

`time` is the standard library package. Defaults keep logs for 30 days, grant five minutes of grace, retry each ping up to three HTTP attempts with ten seconds between attempts, and expire pending pings after ten minutes. Grace is stored in whole seconds and rounded up to whole minutes for Oh Dear.

VariableDefault`OH_DEAR_API_TOKEN`Empty, remote sync disabled without a monitor ID`OH_DEAR_MONITOR_ID``0`, local sync only`OH_DEAR_QUEUE`The application's default queue`OH_DEAR_SEND_STARTING_PING``false``OH_DEAR_RETRY_DELAY_MS``10000``OH_DEAR_API_URL``https://ohdear.app/api``OH_DEAR_PING_ENDPOINT_URL`Use each check's returned ping URL`OH_DEAR_DEBUG_LOGGING``false`Invalid typed environment values stop application startup. Application callbacks override valid environment values. Each application receives its own monitor and schedule. Injected stores must support the concurrency your application uses.

Debugging failed pings
--------------------------------------------------------------------------------------------------------------------------

Enable `OH_DEAR_DEBUG_LOGGING=true` to log failed delivery duration, response status and log ID through `slog`. Unlike the PHP cURL diagnostic mode, logs deliberately omit URLs, authorization headers and response bodies. `OhDearPingFailed` events expose the persisted log, duration and status. Protect stored output and failure messages with application access controls.

Cleaning the database
-----------------------------------------------------------------------------------------------------------------------

The schedule monitor logs every start, finish, failure and skip. After a while the log table might become big. Run `schedule-monitor:prune` to delete logs at or before the retention cutoff. Pending delivery logs are retained until delivered or processed as expired. Pruning leaves task health timestamps intact.

```
func Schedule(ctx context.Context, s *schedule.Schedule) {
    s.Command("schedule-monitor:prune").Daily()
}
```

You may exclude the pruning task itself with `cfg.Tasks["schedule-monitor:prune"] = schedulemonitor.TaskOptions{Ignore: true}`.

Syncing the schedule
--------------------------------------------------------------------------------------------------------------------

Every time you deploy your application, execute:

```
go run . schedule-monitor:sync
```

This command syncs your schedule with the database and optionally Oh Dear. We highly recommend adding it to your deployment script. In a non-production environment, run it manually. Verify the result using `schedule-monitor:list`.

**Running sync without `--keep-old` removes obsolete local tasks and their logs. With Oh Dear configured, it replaces the selected monitor's cron checks, including checks outside this application.**

Use `--keep-old` for non-destructive syncs. This only pushes checks without a local registration timestamp and does not update existing remote definitions or remove remote checks. A remote write followed by a local storage failure may need manual reconciliation. Remote registration writes are not automatically retried.

 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)
