2026-09-14 10:26:09 +01:00
|
|
|
import { IEgressStateRepository } from "@/domain/egress/egress-state.repository.interface.js";
|
2026-09-15 08:42:09 +01:00
|
|
|
import { IJobsRepository } from "@/domain/jobs/job.repository.interface.js";
|
2026-09-14 10:26:09 +01:00
|
|
|
import type { EgressState } from "@/domain/egress/egress.type.js";
|
|
|
|
|
|
|
|
|
|
export interface IEgressStateService {
|
|
|
|
|
getState(): Promise<EgressState>;
|
2026-09-15 08:42:09 +01:00
|
|
|
reset(): Promise<EgressState>;
|
2026-09-14 10:26:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const SERVICE_NAME = "EgressStateService";
|
|
|
|
|
|
2026-09-15 08:42:09 +01:00
|
|
|
// API-process view of the instance-global egress state. Probe-driven transitions are owned by the
|
|
|
|
|
// worker (egress.service.ts); this exists so the controller never touches the repositories.
|
2026-09-14 10:26:09 +01:00
|
|
|
export class EgressStateService implements IEgressStateService {
|
|
|
|
|
static SERVICE_NAME = SERVICE_NAME;
|
|
|
|
|
|
2026-09-15 08:42:09 +01:00
|
|
|
constructor(
|
|
|
|
|
private egressStateRepository: IEgressStateRepository,
|
|
|
|
|
private jobsRepository: IJobsRepository
|
|
|
|
|
) {}
|
2026-09-14 10:26:09 +01:00
|
|
|
|
|
|
|
|
getState = async (): Promise<EgressState> => {
|
|
|
|
|
return this.egressStateRepository.findSingleton();
|
|
|
|
|
};
|
2026-09-15 08:42:09 +01:00
|
|
|
|
|
|
|
|
// Called when the feature is switched on or off: drop any pending recovery job and start from "ok".
|
|
|
|
|
reset = async (): Promise<EgressState> => {
|
2026-09-15 08:59:13 +01:00
|
|
|
await this.jobsRepository.deleteGlobalJob("egress");
|
2026-09-15 08:42:09 +01:00
|
|
|
return this.egressStateRepository.reset();
|
|
|
|
|
};
|
2026-09-14 10:26:09 +01:00
|
|
|
}
|