misc: add scheduled maintenance example

This commit is contained in:
lyc8503 committed 2025-09-27 00:40:19 +08:00
1 parent 65408d4962
commit 4bf07257f2
2 files changed
+31 -2

No files matched your search

+27 -2
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.