scheduler = $scheduler;
$this->settings = $settings;
}
protected function configure(): void
{
$this->addOption(
'ignore-global-lock',
null,
InputOption::VALUE_NONE,
'Ignore global scheduler lock (e.g. when running multiple cron instances)'
);
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
$mode = $this->settings->get('cron.mode', 'disabled');
if ($mode !== 'system') {
$output->writeln('Scheduler not in CRON mode. Skipping CLI execution.');
return Command::SUCCESS;
}
$output->writeln(
sprintf(
'[%s] AcmeShop Scheduler Running...',
Carbon::now()->toJSON(),
)
);
$ignoreGlobalLock = (bool) $input->getOption('ignore-global-lock');
$result = $this->scheduler->run($ignoreGlobalLock);
// Print Executed
if (empty($result->executed)) {
$output->writeln('No tasks executed.');
} else {
foreach ($result->executed as $item) {
$output->writeln(sprintf('Executed: %s (%.4fs)', $item['name'], $item['duration']));
}
}
// Print Failed
foreach ($result->failed as $item) {
$output->writeln(sprintf('Failed: %s - %s', $item['name'], $item['error']));
}
// Print Skipped (verbose only)
if ($output->isVerbose()) {
foreach ($result->skipped as $item) {
$output->writeln(sprintf('Skipped: %s - %s', $item['name'], $item['reason']));
}
}
return Command::SUCCESS;
}
}