<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use Illuminate\Support\Facades\Redis;
use Throwable;

class HealthSchedulerTickCommand extends Command
{
    protected $signature   = 'health:tick';
    protected $description = 'Write a scheduler heartbeat timestamp to Redis for health:check --only=scheduler.';

    public function handle(): int
    {
        try {
            Redis::setex('health:scheduler_last_tick', 300, time());
        } catch (Throwable $e) {
            // Non-fatal — never block the scheduler.
            $this->warn('health:tick could not write to Redis: ' . $e->getMessage());
        }

        return self::SUCCESS;
    }
}
