<?php
use App\Console\Commands\ExpirePrescriptionsCommand;
use App\Console\Commands\PublishScheduledProductsCommand;
use App\Console\Commands\RecoverAbandonedCartsCommand;
use App\Modules\Promotions\Jobs\ExpireLoyaltyPointsJob;
use App\Modules\Payout\Jobs\ProcessScheduledPayoutsJob;
use Illuminate\Support\Facades\Schedule;
/*
|--------------------------------------------------------------------------
| Phase 4 — Console Schedule
|--------------------------------------------------------------------------
| All Phase 4 scheduled tasks are defined here.
| The cPanel cron (Phase 1–3) runs: php artisan schedule:run every minute.
| On VPS (Phase 4): Supervisor/systemd runs: php artisan schedule:work
*/
// Publish products whose scheduled publish_at has passed
Schedule::command(PublishScheduledProductsCommand::class)
->everyFiveMinutes()
->withoutOverlapping()
->runInBackground();
// Abandoned cart recovery — 3h / 24h / 48h sequences
Schedule::command(RecoverAbandonedCartsCommand::class)
->everyThirtyMinutes()
->withoutOverlapping()
->runInBackground();
// Expire loyalty points daily at midnight
Schedule::job(new ExpireLoyaltyPointsJob)
->dailyAt('00:05')
->withoutOverlapping();
// Process vendor payouts daily at 8 AM
Schedule::job(new ProcessScheduledPayoutsJob)
->dailyAt('08:00')
->withoutOverlapping();
// Clean up expired gift cards (mark as expired) — daily
Schedule::call(function () {
\App\Modules\Promotions\Models\GiftCard::where('status', 'active')
->where('expires_at', '<', now())
->update(['status' => 'expired']);
})->daily()->name('expire-gift-cards')->withoutOverlapping();
// Pharmacy: expire approved prescriptions whose valid_until has passed
Schedule::command(ExpirePrescriptionsCommand::class)
->dailyAt('01:00')
->withoutOverlapping()
->runInBackground();
// Queue health check — hourly (logs queue size)
Schedule::call(function () {
$pending = \Illuminate\Support\Facades\DB::table('jobs')->count();
\Illuminate\Support\Facades\Log::info("Queue depth: {$pending} jobs pending");
})->hourly()->name('queue-health-check');