11import { DateTime } from "luxon" ;
2- import { env } from "../env" ;
2+ import { env , ISiteTrackingInfo } from "../env" ;
33
44interface SiteData {
55 downState ?: {
@@ -12,22 +12,24 @@ interface SiteData {
1212}
1313export class SiteMonitor {
1414 siteStatus : Record < string , SiteData > = { } ;
15+ doNotPing : Record < string , boolean > = { } ;
1516 sendMessage : ( msg : string ) => void ;
1617 startupTime = DateTime . local ( { zone : "America/New_York" } ) ;
1718 alertThresholdMs : number ;
1819 pingThresholdMs : number ;
1920
2021 constructor (
21- sites : string [ ] ,
22+ sites : ISiteTrackingInfo [ ] ,
2223 sendMessage : ( msg : string ) => void ,
2324 alertThresholdMs : number ,
2425 pingThresholdMs : number
2526 ) {
26- for ( const siteUrl of sites ) {
27- this . siteStatus [ siteUrl ] = {
27+ for ( const site of sites ) {
28+ this . siteStatus [ site . url ] = {
2829 successfulFetchCount : 0 ,
2930 failedFetchCount : 0 ,
3031 } ;
32+ this . doNotPing [ site . url ] = site . doNotPing ;
3133 }
3234 this . sendMessage = sendMessage ;
3335 this . alertThresholdMs = alertThresholdMs ;
@@ -60,13 +62,14 @@ export class SiteMonitor {
6062 }
6163 if (
6264 + new Date ( ) - downState . firstDownTimestamp >= this . pingThresholdMs &&
63- downState . alertStage === "WARNED"
65+ downState . alertStage === "WARNED" &&
66+ ! this . doNotPing [ siteUrl ]
6467 ) {
6568 downState . alertStage = "PINGED" ;
6669 this . sendMessage (
6770 `<!channel>! ${ siteUrl } has been down for the past ${
6871 this . pingThresholdMs / 1000
69- } seconds with the following errors: ${ downState . failErrors . join ( ", " ) } `
72+ } seconds with ${ downState . failErrors . length } errors `
7073 ) ;
7174 }
7275 }
0 commit comments