50 lines
1.4 KiB
PHP
50 lines
1.4 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace OCA\ChdAdmin\BackgroundJob;
|
|
|
|
use OCA\ChdAdmin\Service\BillingAutoFulfillmentService;
|
|
use OCP\AppFramework\Utility\ITimeFactory;
|
|
use OCP\BackgroundJob\TimedJob;
|
|
use Psr\Log\LoggerInterface;
|
|
|
|
class BillingAutoFulfillmentJob extends TimedJob {
|
|
public function __construct(
|
|
ITimeFactory $time,
|
|
private BillingAutoFulfillmentService $fulfillmentService,
|
|
private LoggerInterface $logger,
|
|
) {
|
|
parent::__construct($time);
|
|
$this->setInterval(5 * 60);
|
|
}
|
|
|
|
protected function run($argument): void {
|
|
try {
|
|
$result = $this->fulfillmentService->runCycle();
|
|
if (empty($result['ok'])) {
|
|
$this->logger->warning('Billing auto-fulfillment job reported an error', [
|
|
'app' => 'chd_admin',
|
|
'status' => $result['status'] ?? '',
|
|
'message' => $result['message'] ?? '',
|
|
]);
|
|
return;
|
|
}
|
|
if ((int)($result['errors'] ?? 0) > 0) {
|
|
$this->logger->warning('Billing auto-fulfillment job completed with errors', [
|
|
'app' => 'chd_admin',
|
|
'processed' => (int)($result['processed'] ?? 0),
|
|
'fulfilled' => (int)($result['fulfilled'] ?? 0),
|
|
'skipped' => (int)($result['skipped'] ?? 0),
|
|
'errors' => (int)($result['errors'] ?? 0),
|
|
]);
|
|
}
|
|
} catch (\Throwable $e) {
|
|
$this->logger->warning('Billing auto-fulfillment job failed', [
|
|
'app' => 'chd_admin',
|
|
'error' => $e->getMessage(),
|
|
]);
|
|
}
|
|
}
|
|
}
|