<?php

declare(strict_types=1);

namespace apexl\Io\modules\cron\Service;

use apexl\Io\modules\cron\Interface\CronAction;
use Throwable;

final readonly class ActionHandler
{
    public function __invoke(CronAction $action): void
    {
        try {
            $action->run();
        } catch (Throwable $e) {
            logger('cron')->error('Cron task failed: {action}: {message}', [
                'action' => $action::class,
                'message' => $e->getMessage(),
                'exception' => $e,
            ]);
        }
    }
}
