Skip to content

Commit

Permalink
feat: Implement smart default onCrash
Browse files Browse the repository at this point in the history
  • Loading branch information
zenflow committed Mar 18, 2021
1 parent a3c8857 commit 5dd2d20
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/interfaces/ServiceConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export interface ServiceConfig {

/**
* A function to be executed each time the service crashes.
* Defaults to `() => {}`.
* Defaults to `ctx => { if (!ctx.isServiceReady) throw new Error('Crashed before becoming ready') }`.
*
* This function is called with an {@link OnCrashContext} object as its only argument.
*
Expand Down
6 changes: 4 additions & 2 deletions src/validateAndNormalizeConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,13 @@ function processServiceConfig(
const merged = {
dependencies: [],
cwd: '.',
// no default command
command: undefined, // no default command
env: process.env,
ready: () => Promise.resolve(),
forceKillTimeout: 5000,
onCrash: () => {},
onCrash: (ctx: OnCrashContext) => {
if (!ctx.isServiceReady) throw new Error('Crashed before becoming ready')
},
logTailLength: 0,
minimumRestartDelay: 1000,
...removeUndefinedProperties(defaults),
Expand Down

0 comments on commit 5dd2d20

Please sign in to comment.