Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/core/pup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 4 additions & 8 deletions lib/core/status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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", <timestamp>] 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", <timestamp>] stores the historical state log.
* @param applicationState The application state to be stored.
*/
public async writeToStore(applicationState: ApiApplicationState) {
Expand All @@ -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)

Expand Down