diff --git a/lib/core/pup.ts b/lib/core/pup.ts index 49c1fb5..182814a 100644 --- a/lib/core/pup.ts +++ b/lib/core/pup.ts @@ -279,7 +279,7 @@ class Pup { const msSinceExited = status.exited ? (new Date().getTime() - status.exited?.getTime()) : Infinity // Default restart delay to 10000ms, except when watching - const baseRestartDelay = config.restartDelayMs ?? config.watch ? 500 : 10000 + const baseRestartDelay = config.restartDelayMs ?? (config.watch ? 500 : 10000) // Calculate exponential backoff if restartBackoffMs is configured let restartDelay = baseRestartDelay diff --git a/lib/core/status.ts b/lib/core/status.ts index 9920bc0..fa5af09 100644 --- a/lib/core/status.ts +++ b/lib/core/status.ts @@ -23,7 +23,7 @@ const started = new Date() */ class Status { private storeName?: string - private lastWrite = Date.now() + private lastWrite = 0 /** * Constructs a new `Status` instance. @@ -36,8 +36,9 @@ class Status { /** * Writes the application status to the KV store with a timestamp as part of the key. * - * Key ["last_application_state"] is written every iteration. - * Key ["application_state", ] is written at most once per 20 seconds. + * Both keys are written at most once per APPLICATION_STATE_WRITE_LIMIT_MS milliseconds. + * Key ["last_application_state"] stores the most recent state (deleted on clean shutdown). + * Key ["application_state", ] stores the historical state log. * @param applicationState The application state to be stored. */ public async writeToStore(applicationState: ApiApplicationState) { @@ -48,11 +49,6 @@ class Status { const kv = new KV({ autoSync: false, disableIndex: true }) await kv.open(this.storeName) - // Initialize lastWrite if it's not set - if (!this.lastWrite) { - this.lastWrite = 0 - } - this.lastWrite = Date.now() await kv.set(["application_state", Date.now()], applicationState)