From 4bf07257f27945f86e0c456bdaba7e225d556342 Mon Sep 17 00:00:00 2001 From: lyc8503 Date: Sat, 27 Sep 2025 00:38:48 +0800 Subject: [PATCH] misc: add scheduled maintenance example --- README.md | 4 ++++ uptime.config.ts | 29 +++++++++++++++++++++++++++-- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 4edee64..2c03d3e 100644 --- a/README.md +++ b/README.md @@ -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 \ No newline at end of file diff --git a/uptime.config.ts b/uptime.config.ts index 65e9356..ddc06f0 100644 --- a/uptime.config.ts +++ b/uptime.config.ts @@ -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.