Merge branch 'main' of https://github.com/lyc8503/UptimeFlare
This commit is contained in:
commit
8a097698be
14 files changed
+288
-101
No files matched your search
+24
-8
@@ -1,6 +1,6 @@
|
||||
import { workerConfig } from '../../uptime.config'
|
||||
import { workerConfig, maintenances } from '../../uptime.config'
|
||||
import { formatStatusChangeNotification, getWorkerLocation, notifyWithApprise } from './util'
|
||||
import { MonitorState, MonitorTarget } from '../../uptime.types'
|
||||
import { MonitorState, MonitorTarget } from '../../types/config'
|
||||
import { getStatus } from './monitor'
|
||||
import { DurableObject } from 'cloudflare:workers'
|
||||
|
||||
@@ -9,7 +9,7 @@ export interface Env {
|
||||
REMOTE_CHECKER_DO: DurableObjectNamespace<RemoteChecker>
|
||||
}
|
||||
|
||||
export default {
|
||||
const Worker = {
|
||||
async scheduled(event: ScheduledEvent, env: Env, ctx: ExecutionContext): Promise<void> {
|
||||
const workerLocation = (await getWorkerLocation()) || 'ERROR'
|
||||
console.log(`Running scheduled event on ${workerLocation}...`)
|
||||
@@ -23,8 +23,7 @@ export default {
|
||||
reason: string
|
||||
) => {
|
||||
// Skip notification if monitor is in the skip list
|
||||
// @ts-ignore
|
||||
const skipList: string[] = workerConfig.notification?.skipNotificationIds
|
||||
const skipList = workerConfig.notification?.skipNotificationIds
|
||||
if (skipList && skipList.includes(monitor.id)) {
|
||||
console.log(
|
||||
`Skipping notification for ${monitor.name} (${monitor.id} in skipNotificationIds)`
|
||||
@@ -32,6 +31,21 @@ export default {
|
||||
return
|
||||
}
|
||||
|
||||
// Skip notification if monitor is in maintenance
|
||||
const maintenanceList = maintenances
|
||||
.filter(
|
||||
(m) =>
|
||||
new Date(timeNow * 1000) >= new Date(m.start) &&
|
||||
(!m.end || new Date(timeNow * 1000) <= new Date(m.end))
|
||||
)
|
||||
.map((e) => (e.monitors || []))
|
||||
.flat()
|
||||
|
||||
if (maintenanceList.includes(monitor.id)) {
|
||||
console.log(`Skipping notification for ${monitor.name} (in maintenance)`)
|
||||
return
|
||||
}
|
||||
|
||||
if (workerConfig.notification?.appriseApiServer && workerConfig.notification?.recipientUrl) {
|
||||
const notification = formatStatusChangeNotification(
|
||||
monitor,
|
||||
@@ -165,7 +179,7 @@ export default {
|
||||
}
|
||||
|
||||
console.log('Calling config onStatusChange callback...')
|
||||
await workerConfig.callbacks.onStatusChange(
|
||||
await workerConfig.callbacks?.onStatusChange(
|
||||
env,
|
||||
monitor,
|
||||
true,
|
||||
@@ -236,7 +250,7 @@ export default {
|
||||
|
||||
if (monitorStatusChanged) {
|
||||
console.log('Calling config onStatusChange callback...')
|
||||
await workerConfig.callbacks.onStatusChange(
|
||||
await workerConfig.callbacks?.onStatusChange(
|
||||
env,
|
||||
monitor,
|
||||
false,
|
||||
@@ -252,7 +266,7 @@ export default {
|
||||
|
||||
try {
|
||||
console.log('Calling config onIncident callback...')
|
||||
await workerConfig.callbacks.onIncident(
|
||||
await workerConfig.callbacks?.onIncident(
|
||||
env,
|
||||
monitor,
|
||||
currentIncident.start[0],
|
||||
@@ -329,6 +343,8 @@ export default {
|
||||
},
|
||||
}
|
||||
|
||||
export default Worker
|
||||
|
||||
export class RemoteChecker extends DurableObject {
|
||||
constructor(ctx: DurableObjectState, env: Env) {
|
||||
super(ctx, env)
|
||||
|
||||
Reference in new issue
Block a user