misc: add scheduled maintenance example

pull/143/head^2
lyc8503 2025-09-27 00:38:48 +08:00
parent 65408d4962
commit 4bf07257f2
2 changed files with 31 additions and 2 deletions

View File

@ -61,3 +61,7 @@ Please refer to [Wiki](https://github.com/lyc8503/UptimeFlare/wiki)
- [ ] Update wiki/README and add docs for dev
- [ ] Migration to Terraform Cloudflare provider version 5.x
- [ ] Cloudflare D1 database
- [x] Scheduled maintenances (via IIFE)
- [ ] Simpler config example
- [ ] Upcoming maintenances
- [ ] Universal Webhook upgrade

View File

@ -102,7 +102,7 @@ const workerConfig: WorkerConfig = {
reason: string
) => {
// This callback will be called when there's a status change for any monitor
// Write any Typescript code here
// Write any TypeScript code here
// This will not follow the grace period settings and will be called immediately when the status changes
// You need to handle the grace period manually if you want to implement it
},
@ -114,7 +114,7 @@ const workerConfig: WorkerConfig = {
reason: string
) => {
// This callback will be called EVERY 1 MINTUE if there's an on-going incident for any monitor
// Write any Typescript code here
// Write any TypeScript code here
},
},
}
@ -140,6 +140,31 @@ const maintenances: MaintenanceConfig[] = [
// [Optional] color of the maintenance alert at status page, default to "yellow"
color: 'blue',
},
// As this config file is a TypeScript file, you can even use IIFE to generate scheduled maintenances
// The following example shows a scheduled maintenance from 2 AM to 4 AM on the 15th of every month (UTC+8)
// This COULD BE DANGEROUS, as generating too many maintenance entries can lead to performance problems
// Undeterministic outputs may also lead to bugs or unexpected behavior
// If you don't know how to DEBUG, use this approach WITH CAUTION
...(function (){
const schedules = [];
const today = new Date();
for (let i = -1; i <= 1; i++) {
// JavaScript's Date object will automatically handle year rollovers
const date = new Date(today.getFullYear(), today.getMonth() + i, 15);
const year = date.getFullYear();
const month = String(date.getMonth() + 1).padStart(2, '0');
schedules.push({
title: `${year}/${parseInt(month)} - Test scheduled maintenance`,
monitors: ['foo_monitor'],
body: 'Monthly scheduled maintenance',
start: `${year}-${month}-15T02:00:00.000+08:00`,
end: `${year}-${month}-15T04:00:00.000+08:00`,
});
}
return schedules;
})()
]
// Don't forget this, otherwise compilation fails.