Squashed commit message
Some checks failed
Telegram Mini App Shop Builder / Compute version metadata (push) Has been cancelled
Telegram Mini App Shop Builder / Run Frontend tests (push) Has been cancelled
Telegram Mini App Shop Builder / Run Backend tests (push) Has been cancelled
Telegram Mini App Shop Builder / Run PHP_CodeSniffer (push) Has been cancelled
Telegram Mini App Shop Builder / Build module. (push) Has been cancelled
Telegram Mini App Shop Builder / release (push) Has been cancelled
Some checks failed
Telegram Mini App Shop Builder / Compute version metadata (push) Has been cancelled
Telegram Mini App Shop Builder / Run Frontend tests (push) Has been cancelled
Telegram Mini App Shop Builder / Run Backend tests (push) Has been cancelled
Telegram Mini App Shop Builder / Run PHP_CodeSniffer (push) Has been cancelled
Telegram Mini App Shop Builder / Build module. (push) Has been cancelled
Telegram Mini App Shop Builder / release (push) Has been cancelled
This commit is contained in:
80
backend/src/console/Commands/ScheduleRunCommand.php
Executable file
80
backend/src/console/Commands/ScheduleRunCommand.php
Executable file
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
namespace Console\Commands;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Acme\ECommerceFramework\Config\Settings;
|
||||
use Acme\ECommerceFramework\Scheduler\SchedulerService;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
class ScheduleRunCommand extends AcmeShopCommand
|
||||
{
|
||||
private SchedulerService $scheduler;
|
||||
private Settings $settings;
|
||||
|
||||
protected static $defaultName = 'schedule:run';
|
||||
protected static $defaultDescription = 'Run scheduled commands';
|
||||
|
||||
public function __construct(SchedulerService $scheduler, Settings $settings)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->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('<comment>Scheduler not in CRON mode. Skipping CLI execution.</comment>');
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
|
||||
$output->writeln(
|
||||
sprintf(
|
||||
'[%s] <info>AcmeShop Scheduler Running...</info>',
|
||||
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('<info>Executed:</info> %s (%.4fs)', $item['name'], $item['duration']));
|
||||
}
|
||||
}
|
||||
|
||||
// Print Failed
|
||||
foreach ($result->failed as $item) {
|
||||
$output->writeln(sprintf('<error>Failed:</error> %s - %s', $item['name'], $item['error']));
|
||||
}
|
||||
|
||||
// Print Skipped (verbose only)
|
||||
if ($output->isVerbose()) {
|
||||
foreach ($result->skipped as $item) {
|
||||
$output->writeln(sprintf('<comment>Skipped:</comment> %s - %s', $item['name'], $item['reason']));
|
||||
}
|
||||
}
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user