-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathRunTaskCommand.php
More file actions
41 lines (35 loc) · 1.2 KB
/
RunTaskCommand.php
File metadata and controls
41 lines (35 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php
declare(strict_types=1);
namespace App\Command;
use App\Repository\TaskRepository;
use App\Service\TaskRunner;
use Psr\Log\LoggerInterface;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Attribute\Option;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Output\OutputInterface;
#[AsCommand(name: 'app:task:run', description: 'Run scheduled tasks')]
final class RunTaskCommand
{
public function __construct(
private readonly TaskRepository $repository,
private readonly TaskRunner $taskRunner,
private readonly LoggerInterface $logger,
) {
}
public function __invoke(
OutputInterface $output,
#[Option(name: 'limit', shortcut: 'l', description: 'Limit the number of tasks to run')]
int $limit = 10,
): int {
foreach ($this->repository->getTasksToVerify($limit) as $task) {
try {
$this->taskRunner->run($task);
} catch (\Exception $e) {
$this->logger->error('Failed running task', ['exception' => $e]);
$output->writeln($e->getMessage());
}
}
return Command::SUCCESS;
}
}