error('This command is only functional in self-hosted mode. Please set SELF_HOSTED=true in your .env file.'); Log::warning('SchedulerStatusCommand: Attempted to run in non-self-hosted mode.'); return \Illuminate\Console\Command::FAILURE; } $mode = $this->option('mode'); if ($mode === self::MODE_RECORD) { Cache::put(self::CACHE_KEY_LAST_RUN, Carbon::now()->getTimestamp(), Carbon::now()->addHours(2)); $this->info('Scheduler last run timestamp recorded.'); Log::info('SchedulerStatusCommand: Recorded last run timestamp.'); return \Illuminate\Console\Command::SUCCESS; } // Default to 'check' mode (this covers explicit 'check' or any other value for mode) $lastRunTimestamp = Cache::get(self::CACHE_KEY_LAST_RUN); if (!$lastRunTimestamp) { $this->error('Scheduler last run timestamp not found.'); Log::warning('SchedulerStatusCommand: Last run timestamp not found during check.'); return \Illuminate\Console\Command::FAILURE; } $maxMinutes = (int) $this->option('max-minutes'); if (Carbon::now()->getTimestamp() - $lastRunTimestamp > $maxMinutes * 60) { $this->error("Scheduler last ran more than {$maxMinutes} minutes ago. Last run: " . Carbon::createFromTimestamp($lastRunTimestamp)->diffForHumans()); Log::warning("SchedulerStatusCommand: Health check failed. Last ran more than {$maxMinutes} minutes ago."); return \Illuminate\Console\Command::FAILURE; } $this->info('Scheduler is healthy. Last ran: ' . Carbon::createFromTimestamp($lastRunTimestamp)->diffForHumans()); return \Illuminate\Console\Command::SUCCESS; } }