Files
emails/cli/common/Command/Jobs/Execute.php
2023-06-12 21:14:07 -04:00

42 lines
1.1 KiB
PHP

<?php
namespace ProVM\Command\Jobs;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use ProVM\Service\Jobs;
#[AsCommand(
name: 'jobs:execute',
description: 'Execute job by job_id',
hidden: false
)]
class Execute extends Command
{
public function __construct(protected Jobs $service, string $name = null)
{
parent::__construct($name);
}
protected function configure()
{
$this->addArgument('job_id', InputArgument::REQUIRED, 'Job ID to be executed');
}
public function execute(InputInterface $input, OutputInterface $output)
{
$io = new SymfonyStyle($input, $output);
$job_id = $input->getArgument('job_id');
$job = $this->service->get($job_id);
if ($this->service->run($job)) {
$io->success('Success');
} else {
$io->error('Failed');
}
return Command::SUCCESS;
}
}