# Scheduled Tasks & Console Commands

## Scheduled Cron Jobs
Defined in `routes/console.php` — 17 scheduled tasks:

| Command | Schedule | Purpose |
|---------|----------|---------|
| `notifications:marathon-upcoming` | Daily 08:00 | Marathons starting/ending within 24h |
| `notifications:assessment-upcoming` | Hourly | Assessments starting/ending within 1h |
| `marathons:complete-expired` | Hourly | Auto-complete past marathons |
| `events:close-expired` | Hourly | Lock expired competitions |
| `events:open-scheduled` | Every 15 min | Unlock scheduled competitions |
| `notifications:plan-expiring` | Daily 06:00 | Subscriptions expiring in 7/1 day |
| `notifications:plan-expired` | Daily 00:30 | Deactivate expired subscriptions |
| `subscriptions:process-grace-period` | Daily 02:00 | Process grace period expiration |
| `notifications:feature-limit` | Daily 12:00 | Feature usage limit warnings |
| `usage:snapshot` | Daily 23:55 | Record daily usage snapshots |
| `notifications:verification-reminder` | Daily 10:00 | Remind unverified users |
| `notifications:trial-ending` | Daily 07:00 | Trial ending reminders |
| `notifications:storage-warning` | Weekly Mon 09:00 | Storage >80% warning |
| `subscriptions:auto-suspend` | Daily 00:00 | Suspend past grace period, expire 30d+ |
| `notifications:cleanup-logs` | Monthly 1st 03:00 | Delete 90d+ notification logs |

All commands use `withoutOverlapping()` to prevent concurrent execution.

## Console Commands (`app/Console/Commands/`)

### Notification Commands
- `SendAssessmentUpcomingNotifications` — Assessment start/end notifications
- `SendMarathonUpcomingNotifications` — Marathon start/end notifications
- `SendPlanExpiringNotifications` — Subscription expiring notifications
- `SendPlanExpiredNotifications` — Subscription expired notifications
- `SendTrialEndingNotifications` — Trial ending notifications
- `SendFeatureLimitNotifications` — Feature usage limit notifications
- `SendVerificationReminderNotifications` — Verification reminders
- `SendStorageWarningNotifications` — Storage usage warnings

### Subscription Commands
- `SuspendExpiredSubscriptions` — Mark expired subscriptions as suspended
- `ProcessGracePeriodSubscriptions` — Process grace period end

### Event Commands
- `CloseExpiredEvents` — Lock expired events (competitions, marathon-competitions)
- `OpenScheduledEvents` — Unlock scheduled events at start time (every 15 min)
- `CompleteExpiredMarathons` — Auto-complete marathons past end date

### Maintenance Commands
- `RecordUsageSnapshot` — Record daily feature usage snapshots
- `CleanupNotificationLogs` — Delete old notification logs

### Utilities
- `ValidateNotificationEngineSystem` — Validate notification engine configuration

## Notification Engine Console
- `RetryFailedNotificationsCommand` (`app/NotificationEngine/Console/RetryFailedNotificationsCommand.php`) — Retry failed notifications
