-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathExpireMatchFunds.php
More file actions
53 lines (45 loc) · 1.9 KB
/
Copy pathExpireMatchFunds.php
File metadata and controls
53 lines (45 loc) · 1.9 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
<?php
declare(strict_types=1);
namespace MatchBot\Application\Commands;
use MatchBot\Domain\DonationRepository;
use MatchBot\Domain\DonationService;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Lock\Exception\LockConflictedException;
/**
* Expire match funding allocations, by hard-deleting `FundingWithdrawals` for donations that have been
* Pending for more than the reservation time and releasing funds with the real-time adapter.
*
* Donations may still be completed after the expiry time but will not receive match funds.
*/
#[AsCommand(
name: 'matchbot:expire-match-funds',
description: 'Frees up match funding from stale Pending donations'
)]
class ExpireMatchFunds extends LockingCommand
{
public function __construct(
private DonationRepository $donationRepository,
private DonationService $donationService,
) {
parent::__construct();
}
#[\Override]
protected function doExecute(InputInterface $input, OutputInterface $output): int
{
$toRelease = $this->donationRepository->findWithExpiredMatching(new \DateTimeImmutable('now'));
foreach ($toRelease as $donationUUID) {
try {
$this->donationService->releaseMatchFundsInTransaction($donationUUID);
} catch (LockConflictedException $conflictedException) {
// It's OK, we won't release the funds now on this donation which seems to be in the process of being
// confirmed. Either it will be confirmed right now, or we can try again to releaese funds when this runs
// again next minute if the confirmation fails.
}
}
$numberExpired = count($toRelease);
$output->writeln("Released $numberExpired donations' matching");
return 0;
}
}