-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCallFrequentTasks.php
More file actions
68 lines (59 loc) · 2.06 KB
/
Copy pathCallFrequentTasks.php
File metadata and controls
68 lines (59 loc) · 2.06 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
declare(strict_types=1);
namespace MatchBot\Application\Commands;
use Psr\Log\LoggerInterface;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Lock\LockFactory;
#[AsCommand(
name: 'matchbot:tick',
description: 'Calls all per-minute commands; currently to expire old matching and send statistics'
)]
class CallFrequentTasks extends LockingCommand
{
/** @var list<\MatchBot\Application\Commands\Command> */
private array $commands;
public function __construct(
private LockFactory $lockFactory,
private LoggerInterface $logger,
SendStatistics $sendStatistics,
ExpireMatchFunds $expireMatchFunds,
ExpirePendingMandates $expirePendingMandates,
CancelStaleDonationFundTips $cancelStaleDonationFundTips,
UpdateCampaignDonationStats $updateCampaignDonationStats,
DeleteOldTestFunds $deleteOldTestFunds,
UpdateApproxCampaignStatus $updateApproxCampaignStatus,
) {
parent::__construct();
$this->commands = [
$sendStatistics,
$expireMatchFunds,
$expirePendingMandates,
$cancelStaleDonationFundTips,
$updateCampaignDonationStats,
$deleteOldTestFunds,
$updateApproxCampaignStatus,
];
}
#[\Override]
protected function doExecute(InputInterface $input, OutputInterface $output): int
{
foreach ($this->commands as $command) {
if ($command instanceof LockingCommand) {
$command->setLockFactory($this->lockFactory);
$command->setLogger($this->logger);
}
$return = $command->run(
new ArrayInput([]),
$output
);
if ($return !== 0) {
$output->writeln("Failed run {$command->getName()}");
return $return;
}
}
return 0;
}
}