feat: make cooldown optional and remove it from simple config
parent
9401202575
commit
70ad2e8677
|
|
@ -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
|
||||||
|
|
|
||||||
|
|
@ -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',
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue