- Schedule the recovery job before recording the degraded transition,
so a crash between the two leaves a stray row (removed on the job's
first run) rather than a degraded state nothing is polling
- Count any HTTP response, including 4xx/5xx, as reachable for http
targets; only a transport failure counts against egress
- Cascade a deleted notification out of egressNotifications with an
atomic $pull in the settings repository, after the team-scoped delete
- Handle two processes racing the first egress state insert
- Address global job rows by one key (deleteGlobalJob on _id) and
restore the deleteByIdAndType signature
- Inject net into PingProvider like PortProvider
- Integration tests for MongoEgressStateRepository and the global-row
delete methods on the jobs repository
🔧
32 lines
1.1 KiB
TypeScript
32 lines
1.1 KiB
TypeScript
import { IEgressStateRepository } from "@/domain/egress/egress-state.repository.interface.js";
|
|
import { IJobsRepository } from "@/domain/jobs/job.repository.interface.js";
|
|
import type { EgressState } from "@/domain/egress/egress.type.js";
|
|
|
|
export interface IEgressStateService {
|
|
getState(): Promise<EgressState>;
|
|
reset(): Promise<EgressState>;
|
|
}
|
|
|
|
const SERVICE_NAME = "EgressStateService";
|
|
|
|
// 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.
|
|
export class EgressStateService implements IEgressStateService {
|
|
static SERVICE_NAME = SERVICE_NAME;
|
|
|
|
constructor(
|
|
private egressStateRepository: IEgressStateRepository,
|
|
private jobsRepository: IJobsRepository
|
|
) {}
|
|
|
|
getState = async (): Promise<EgressState> => {
|
|
return this.egressStateRepository.findSingleton();
|
|
};
|
|
|
|
// Called when the feature is switched on or off: drop any pending recovery job and start from "ok".
|
|
reset = async (): Promise<EgressState> => {
|
|
await this.jobsRepository.deleteGlobalJob("egress");
|
|
return this.egressStateRepository.reset();
|
|
};
|
|
}
|