feat: make cooldown optional and remove it from simple config

pull/161/head
lyc8503 2025-11-05 23:10:18 +08:00
parent 9401202575
commit 70ad2e8677
4 changed files with 3 additions and 5 deletions

View File

@ -46,7 +46,7 @@ export type MonitorTarget = {
} }
export type WorkerConfig<TEnv = Env> = { export type WorkerConfig<TEnv = Env> = {
kvWriteCooldownMinutes: number kvWriteCooldownMinutes?: number
passwordProtection?: string passwordProtection?: string
monitors: MonitorTarget[] monitors: MonitorTarget[]
notification?: Notification notification?: Notification

View File

@ -27,7 +27,7 @@ const pageConfig: PageConfig = {
} }
const workerConfig: WorkerConfig = { const workerConfig: WorkerConfig = {
// Write KV at most every 3 minutes unless the status changed // [Optional] Write KV at most every N minutes unless the status changed, default to 3
kvWriteCooldownMinutes: 3, kvWriteCooldownMinutes: 3,
// Enable HTTP Basic auth for status page & API by uncommenting the line below, format `<USERNAME>:<PASSWORD>` // Enable HTTP Basic auth for status page & API by uncommenting the line below, format `<USERNAME>:<PASSWORD>`
// passwordProtection: 'username:password', // passwordProtection: 'username:password',

View File

@ -17,8 +17,6 @@ const pageConfig: PageConfig = {
} }
const workerConfig: WorkerConfig = { const workerConfig: WorkerConfig = {
// Write KV at most every 3 minutes unless the status changed
kvWriteCooldownMinutes: 3,
// Define all your monitors here // Define all your monitors here
monitors: [ monitors: [
// Example HTTP Monitor // Example HTTP Monitor

View File

@ -331,7 +331,7 @@ const Worker = {
// Allow for a cooldown period before writing to KV // Allow for a cooldown period before writing to KV
if ( if (
statusChanged || statusChanged ||
currentTimeSecond - state.lastUpdate >= workerConfig.kvWriteCooldownMinutes * 60 - 10 // Allow for 10 seconds of clock drift currentTimeSecond - state.lastUpdate >= (workerConfig.kvWriteCooldownMinutes ?? 3) * 60 - 10 // Allow for 10 seconds of clock drift
) { ) {
console.log('Updating state...') console.log('Updating state...')
state.lastUpdate = currentTimeSecond state.lastUpdate = currentTimeSecond