add abstract class with default timeout and helper method
This commit is contained in:
1 parent
7998bae87d
commit
0bb3320010
1 file changed
+23
@@ -1,7 +1,30 @@
|
||||
import type { Notification } from "@/types/index.js";
|
||||
import type { NotificationMessage } from "@/types/notificationMessage.js";
|
||||
import { ILogger } from "@/utils/logger.js";
|
||||
import type { OptionsOfJSONResponseBody } from "got";
|
||||
|
||||
export const DEFAULT_NOTIFICATION_TIMEOUT_MS = 30_000;
|
||||
export interface INotificationProvider {
|
||||
sendMessage: (notification: Notification, message: NotificationMessage) => Promise<boolean>;
|
||||
sendTestAlert(notification: Partial<Notification>): Promise<boolean>;
|
||||
}
|
||||
|
||||
export abstract class NotificationProvider implements INotificationProvider {
|
||||
protected readonly logger: ILogger;
|
||||
protected readonly timeoutMs: number;
|
||||
|
||||
constructor(logger: ILogger, timeoutMs: number = DEFAULT_NOTIFICATION_TIMEOUT_MS) {
|
||||
this.logger = logger;
|
||||
this.timeoutMs = timeoutMs;
|
||||
}
|
||||
|
||||
protected gotRequestOptions(): Pick<OptionsOfJSONResponseBody, "timeout" | "retry"> {
|
||||
return {
|
||||
timeout: { request: this.timeoutMs },
|
||||
retry: { limit: 0 },
|
||||
};
|
||||
}
|
||||
|
||||
abstract sendMessage(notification: Notification, message: NotificationMessage): Promise<boolean>;
|
||||
abstract sendTestAlert(notification: Partial<Notification>): Promise<boolean>;
|
||||
}
|
||||
Reference in new issue
Block a user