# Scheduled Tasks

Turista relies on Laravel's task scheduler for background jobs. A cron entry must call `schedule:run` every minute.

## Cron entry

```cron
* * * * * cd /path/to/turista && php artisan schedule:run >> /dev/null 2>&1
```

## Registered commands

Commands are defined in `routes/console.php`.

### Release expired pending reservations

```php
Schedule::command('pending-reservations:release-expired')->everyFiveMinutes()->withoutOverlapping();
```

Finds pending reservations whose `expires_at` has passed and releases their held availability so the units can be booked again.

### Send due notifications

```php
Schedule::command('notifications:send-due')->everyFiveMinutes()->withoutOverlapping();
```

Claims `ScheduledNotification` rows whose `send_at` has passed and dispatches `DispatchScheduledNotification` jobs to the queue.

> **Production note:** Append `->onOneServer()` to both scheduled commands when running a single scheduler leader with a shared cache store, so the work is not duplicated across multiple app servers.

## Queue workers

Scheduled commands dispatch jobs to the queue. Ensure a queue worker is running:

```bash
php artisan queue:work --sleep=3 --tries=3
```

For production, use Supervisor or systemd to keep the worker alive.

## Monitoring

- Check `storage/logs/laravel.log` for scheduler or worker errors.
- Verify the cron daemon is running.
- Verify the queue worker process is running.
- Use `php artisan queue:monitor` or a monitoring service to alert on queue length.
