1 const FIVE_MINUTES_IN_MILLISECONDS = 5 * 60 * 1000;
3 export enum AvailabilityTypes {
9 export type AvailabilityReport = {
10 [AvailabilityTypes.SENTRY]: boolean;
11 [AvailabilityTypes.ERROR]: boolean;
12 [AvailabilityTypes.CRITICAL]: boolean;
14 export class Availability {
15 static status: Map<AvailabilityTypes, number> = new Map();
17 static interval: ReturnType<typeof setInterval>;
19 static init = (report: (status: AvailabilityReport) => void, interval: number = FIVE_MINUTES_IN_MILLISECONDS) => {
21 this.interval = setInterval(() => {
22 const sentry = this.status.get(AvailabilityTypes.SENTRY);
23 const error = this.status.get(AvailabilityTypes.ERROR);
24 const critical = this.status.get(AvailabilityTypes.CRITICAL);
26 [AvailabilityTypes.SENTRY]: sentry !== undefined && Date.now() - sentry > FIVE_MINUTES_IN_MILLISECONDS,
27 [AvailabilityTypes.ERROR]: error !== undefined && Date.now() - error > FIVE_MINUTES_IN_MILLISECONDS,
28 [AvailabilityTypes.CRITICAL]:
29 critical !== undefined && Date.now() - critical > FIVE_MINUTES_IN_MILLISECONDS,
34 static mark = (type: AvailabilityTypes) => {
35 this.status.set(type, Date.now());
38 static clear = () => {
39 clearInterval(this.interval);
40 this.status = new Map();