Jobs setup
This commit is contained in:
41
cli/common/Command/Jobs/Execute.php
Normal file
41
cli/common/Command/Jobs/Execute.php
Normal file
@ -0,0 +1,41 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user