directorytree/cadence
Cadence adds model-based scheduling to Laravel. Attach one or more cron or RRULE schedules to any Eloquent model, track due runs, and dispatch events when schedules trigger. Driver-based design supports cron, php-rrule, Recurr, or custom drivers.
Cadence aligns well with Laravel’s Eloquent-centric and event-driven architecture, making it ideal for applications requiring model-specific scheduling (e.g., user notifications, report generation, compliance checks). Its driver-based design (cron/RRULE) ensures flexibility without vendor lock-in, while the polymorphic schedulable relationship enables seamless integration with existing models. The package leverages Laravel’s queue system and event listeners, reducing boilerplate for async execution.
Key Synergies:
HasSchedules trait and polymorphic relations.ScheduleTriggered events decouple scheduling from business logic, enabling async processing (queued jobs, notifications).tap() methods allow domain-specific adaptations (e.g., business rule-based scheduling).Low-Medium Effort:
schedules:run command to routes/console.php, and implementing Schedulable on target models (~2–4 hours for a TPM to coordinate).php-rrule for RRULE support). Cron is pre-required via Laravel core.Compatibility:
schedules table (no schema conflicts with existing apps).| Risk Area | Severity | Mitigation |
|---|---|---|
| Performance at Scale | Medium | Pre-computed next_run_at optimizes queries, but high-volume schedules may require indexing or batching. |
| Timezone Edge Cases | Low | Carbon handles DST transitions, but custom logic may be needed for niche regions. |
| Event Listener Complexity | Low | Event discovery reduces boilerplate; shouldQueue() enables granular control. |
| Driver Dependencies | Low | Optional drivers (e.g., php-rrule) are well-maintained; cron is core. |
| Migration Upgrades | Low | Versioned migrations (e.g., disabled_at in v1.1.0) are backward-compatible. |
| Concurrency | Medium | withoutOverlapping() in schedules:run prevents race conditions, but custom drivers must handle thread safety. |
Critical Questions for TPM:
ScheduleTriggered listeners) be retried/alerted?Cadence is optimized for Laravel’s native stack:
schedules table (no ORM conflicts).ShouldQueue listeners).schedules:run command for CLI-driven execution.Non-Laravel Considerations:
php-rrule for RRULE). Cron is pre-included via Laravel.| Phase | Tasks | Effort | Dependencies |
|---|---|---|---|
| Discovery | Audit existing cron jobs/events to identify model-specific scheduling candidates. | Low | Business teams |
| Setup | Install package, publish migrations, add schedules:run to routes/console.php. |
Medium | DevOps (for cron setup) |
| Model Integration | Implement Schedulable on target models (e.g., Report, Subscription). |
Low | Backend devs |
| Driver Configuration | Choose/cfg drivers (cron/RRULE) and install optional deps (e.g., php-rrule). |
Low | Package manager |
| Event Listeners | Create listeners for ScheduleTriggered (e.g., dispatch jobs, send emails). |
Medium | Backend/Queue devs |
| Testing | Validate schedules fire correctly (unit/integration tests for drivers, listeners). | High | QA/Backend |
| Deployment | Schedule schedules:run in deployment pipeline (e.g., every minute via cron or Laravel Forge). |
Low | DevOps |
| Observability | Add logging/monitoring for triggered schedules (e.g., Laravel Horizon, Datadog). | Medium | Observability team |
Sequencing Recommendations:
Report) to validate integration.| Component | Compatibility | Notes |
|---|---|---|
| Laravel | 11.x+ (tested). Avoid pre-11 due to event/queue changes. | Use composer require laravel/framework:^11.0. |
| PHP | 8.2+ (required). | No polyfills needed. |
| Databases | MySQL, PostgreSQL, SQLite (Eloquent-supported). | No schema conflicts. |
| Queue Drivers | All Laravel-supported (database, redis, etc.). | Async listeners work with any driver. |
| Timezones | All IANA timezones (Carbon-supported). | Test edge cases (e.g., DST transitions). |
| Custom Drivers | Extendable via Schedule base class. |
Requires PHP 8.2+ features (e.g., enums). |
Potential Conflicts:
ScheduleTriggered listeners don’t conflict with existing event handlers.| Aspect | Impact | Mitigation |
|---|---|---|
| Migrations | Minimal; single schedules table. |
Use Laravel’s migration rollback for changes. |
| Driver Updates | Optional dependencies (e.g., php-rrule) may require updates. |
Monitor Packagist for breaking changes. |
| Schedule Management | Manual via code (e.g., addSchedule()) or admin UI (if built). |
Consider a custom admin panel for non-dev users. |
| Timezone Changes | Requires updating schedules if timezone rules change (e.g., DST policy updates). | Document timezone strategies per model. |
| Custom Drivers | May need updates if underlying libraries change (e.g., Recurr). |
Isolate custom logic in feature branches. |
| Issue Type | Likelihood | Resolution Path |
|---|---|---|
| Schedules Not Firing | Medium | Check schedules:run command execution, next_run_at timestamps, and timezone. |
| Event Listener Failures | High | Use Laravel’s queue failure channels (e.g., database, Slack) and retry logic. |
How can I help you explore Laravel packages today?