Observability and operations – Scheduled tasks with monitoring
This section describes how the Laravel scheduler drives critical operational jobs in production, and how Sentry’s sentryMonitor() macro tracks their health. Scheduled tasks cover marketing, attendance confirmations, scorecards, texting, partner roster sends, and more.
Scheduler entry point
Laravel loads console routes in bootstrap/app.php, pointing to routes/console.php.
All scheduled commands and jobs live there and are registered via the Schedule facade .
Defining scheduled jobs
Use the Schedule facade to register commands or jobs with a cron-like API.
A typical entry looks like this:
use Illuminate\Support\Facades\Schedule;
Schedule::command('event:sendPackets')
->dailyAt('17:00')
->sentryMonitor()
->onOneServer();
Each call returns a Schedule\Event instance, enabling fluent chaining .
Sentry monitoring integration
The sentryMonitor() macro instruments each scheduled event to:
- Start a Sentry transaction when the task begins.
- Capture any exceptions or errors during execution.
- Log performance metrics (duration, outcomes).
This macro is provided by the sentry/sentry-laravel package (installed via Composer) . It ensures that task failures or anomalies surface in Sentry’s dashboard.
Key scheduling patterns
| Feature | Purpose |
|---|---|
| ⏰ dailyAt/weeklyOn | Precise cron scheduling |
| sentryMonitor() | Health tracking and error reporting |
| onOneServer() | Prevent duplicate execution in clusters |
| withoutOverlapping | Avoid overlapping runs (e.g. everyMinute jobs) |
| name('…') | Label jobs for easier identification in logs/dashboards |
Categories of scheduled work
- Marketing
Campaign syncs and sheet exports. - Attendance & Reminders
QR-code reminders, check-in links, ticket emails. - Reporting
Weekly scorecards, partner roster sends. - Sync jobs
Stripe payments, EventConnect integration, Braze. - Utility
Database backups, cache warming, duplicate-finder.
Execution flow
Below is a simplified flowchart of a monitored task run:
flowchart TD
subgraph Scheduler
A[cron: /etc/cron.d/laravel-schedule] --> B[php artisan schedule:run]
end
B --> C[Schedule Manager]
C --> D[Event Dispatcher]
D --> E[Scheduled Task Event]
E --> F[sentryMonitor Wrapper]
F --> G[onOneServer Lock]
G --> H[Execute Command or Job]
H --> I{Success or Exception}
I -->|Exception| J[Sentry.captureException]
I -->|Success| K[Sentry.finishTransaction]
Best practices
- Always add
sentryMonitor()to critical jobs. - Use
onOneServer()in multi-host setups. - Label jobs via
name()for easy filtering in Sentry. - Use
withoutOverlapping()when tasks may exceed their schedule. - Group related tasks logically to simplify monitoring dashboards.
By consistently instrumenting scheduled tasks with Sentry and leveraging Laravel’s scheduler features, the platform maintains high observability, rapid alerting, and robust operational tooling.