2024-08-27 12:33:15 +00:00
|
|
|
import OneUptimeDate from "Common/Types/Date";
|
2024-06-14 11:09:53 +00:00
|
|
|
import Dictionary from "Common/Types/Dictionary";
|
|
|
|
import BadDataException from "Common/Types/Exception/BadDataException";
|
|
|
|
import { PromiseVoidFunction } from "Common/Types/FunctionTypes";
|
2024-01-11 10:49:55 +00:00
|
|
|
|
|
|
|
export default class JobDictionary {
|
2024-06-14 11:09:53 +00:00
|
|
|
private static dictionary: Dictionary<PromiseVoidFunction> = {};
|
2024-01-11 10:49:55 +00:00
|
|
|
|
2024-08-27 12:33:15 +00:00
|
|
|
private static timeoutInMsDictionary: Dictionary<number> = {};
|
|
|
|
|
2024-06-14 11:09:53 +00:00
|
|
|
public static getJobFunction(name: string): PromiseVoidFunction {
|
|
|
|
if (this.dictionary[name]) {
|
|
|
|
return this.dictionary[name] as PromiseVoidFunction;
|
2024-01-11 10:49:55 +00:00
|
|
|
}
|
|
|
|
|
2024-06-14 11:09:53 +00:00
|
|
|
throw new BadDataException("No job found with name: " + name);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static setJobFunction(name: string, job: PromiseVoidFunction): void {
|
|
|
|
this.dictionary[name] = job;
|
|
|
|
}
|
2024-08-27 12:33:15 +00:00
|
|
|
|
|
|
|
public static getTimeoutInMs(name: string): number {
|
|
|
|
const defaultTimeInMs: number =
|
|
|
|
OneUptimeDate.convertMinutesToMilliseconds(5);
|
|
|
|
if (this.timeoutInMsDictionary[name]) {
|
|
|
|
return this.timeoutInMsDictionary[name] || defaultTimeInMs;
|
|
|
|
}
|
|
|
|
|
|
|
|
return defaultTimeInMs; // by default every job timeout is 5 minutes
|
|
|
|
}
|
|
|
|
|
|
|
|
public static setTimeoutInMs(name: string, timeoutInMs: number): void {
|
|
|
|
this.timeoutInMsDictionary[name] = timeoutInMs;
|
|
|
|
}
|
2024-01-11 10:49:55 +00:00
|
|
|
}
|