You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
1.3 KiB
PHP
41 lines
1.3 KiB
PHP
<?php
|
|
namespace App\Command;
|
|
|
|
use App\Services\Cloud\CloudWorkerService;
|
|
use App\Services\Cloud\CloudInvoiceService;
|
|
|
|
final class CloudWorker
|
|
{
|
|
public static function run(array $argv = []): int
|
|
{
|
|
$once = in_array('--once', $argv, true);
|
|
$policyOnly = in_array('--policy-only', $argv, true);
|
|
$worker = new CloudWorkerService(null, $policyOnly);
|
|
do {
|
|
try {
|
|
$worked = $worker->tick();
|
|
} catch (\Throwable $error) {
|
|
fwrite(STDERR, 'cloud worker temporarily unavailable: ' . get_class($error) . PHP_EOL);
|
|
if ($once) {
|
|
return 1;
|
|
}
|
|
$worked = false;
|
|
}
|
|
// SMTP is deliberately isolated from the lifecycle process so a
|
|
// slow mail server can never delay expiry or traffic policies.
|
|
if (!$policyOnly) {
|
|
try {
|
|
CloudInvoiceService::deliverReminders(1);
|
|
} catch (\Throwable $error) {
|
|
fwrite(STDERR, 'cloud invoice mail temporarily unavailable: '
|
|
. get_class($error) . PHP_EOL);
|
|
}
|
|
}
|
|
if (!$once && !$worked) {
|
|
usleep(1000000);
|
|
}
|
|
} while (!$once);
|
|
return 0;
|
|
}
|
|
}
|