Files
proxmox-selfservice/support-provisioning-portal/includes/class-spp-expiration-service.php
2026-04-23 12:39:36 +02:00

32 lines
829 B
PHP

<?php
if (!defined('ABSPATH')) {
exit;
}
final class SPP_Expiration_Service
{
public function __construct(
private SPP_Repository $repository,
private SPP_Proxmox_Client $proxmox
) {
}
public function expire_due_deployments(): void
{
foreach ($this->repository->due_for_expiration() as $deployment) {
$stop_error = null;
if (!empty($deployment['proxmox_vm_id']) && $deployment['status'] !== 'STOPPED') {
try {
$this->proxmox->stop_vm((int) $deployment['proxmox_vm_id']);
} catch (Throwable $error) {
$stop_error = $error->getMessage();
}
}
$this->repository->mark_deployment_expired((int) $deployment['id'], $stop_error);
}
}
}