53 lines
1.6 KiB
PHP
53 lines
1.6 KiB
PHP
<?php
|
|
namespace ProVM\Command\Jobs;
|
|
|
|
use Symfony\Component\Console\Attribute\AsCommand;
|
|
use Symfony\Component\Console\Command\Command;
|
|
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:check',
|
|
description: 'Check for pending jobs',
|
|
hidden: false
|
|
)]
|
|
class Check extends Command
|
|
{
|
|
public function __construct(protected Jobs $service, string $name = null)
|
|
{
|
|
parent::__construct($name);
|
|
}
|
|
|
|
public function execute(InputInterface $input, OutputInterface $output)
|
|
{
|
|
$section1 = $output->section();
|
|
$section2 = $output->section();
|
|
$io1 = new SymfonyStyle($input, $section1);
|
|
$io2 = new SymfonyStyle($input, $section2);
|
|
$io1->title('Checking Pending Jobs');
|
|
$pending_jobs = $this->service->getPending();
|
|
$notice = 'Found ' . count($pending_jobs) . ' jobs';
|
|
$io1->text($notice);
|
|
if (count($pending_jobs) > 0) {
|
|
$io1->section('Running Jobs');
|
|
$io1->progressStart(count($pending_jobs));
|
|
foreach ($pending_jobs as $job) {
|
|
$section2->clear();
|
|
$io2->text("Running {$job->command}");
|
|
if ($this->service->run($job)) {
|
|
$io2->success('Success');
|
|
} else {
|
|
$io2->error('Failure');
|
|
}
|
|
$io1->progressAdvance();
|
|
}
|
|
}
|
|
$section2->clear();
|
|
$io2->success('Done');
|
|
|
|
return Command::SUCCESS;
|
|
}
|
|
}
|