Skip to content

Commit

Permalink
zinnia: add restart module on inactivity (#433)
Browse files Browse the repository at this point in the history
* zinnia: add restart module on inactivity

* reorder

* clear timeout on abort
  • Loading branch information
juliangruber authored May 3, 2024
1 parent 2f82038 commit 194a790
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion lib/zinnia.js
Original file line number Diff line number Diff line change
Expand Up @@ -365,8 +365,23 @@ export async function run ({
)
childProcesses.push(Object.assign(childProcess, { moduleName: module }))

let timeoutId
const resetTimeout = () => {
clearTimeout(timeoutId)
timeoutId = setTimeout(() => {
onActivity({
type: 'error',
message: `${capitalize(module)} has been inactive for 5 minutes, restarting...`
})
controller.abort()
}, 5 * 60 * 1000)
}
resetTimeout()
signal.addEventListener('abort', () => clearTimeout(timeoutId))

childProcess.stdout.setEncoding('utf-8')
childProcess.stdout.on('data', data => {
resetTimeout()
handleEvents({
module,
contracts,
Expand All @@ -379,7 +394,11 @@ export async function run ({
Sentry.captureException(err)
})
})
childProcess.stderr.pipe(process.stderr, { end: false })
childProcess.stderr.setEncoding('utf-8')
childProcess.stderr.on('data', data => {
resetTimeout()
process.stderr.write(data)
})

childProcess.on('exit', (code, signal) => {
const exitReason = signal ? `via signal ${signal}` : `with code: ${code}`
Expand Down

0 comments on commit 194a790

Please sign in to comment.