Skip to content

Instantly share code, notes, and snippets.

View tiagoluizpoli's full-sized avatar

Tiago Luiz Seuaciuc de Poli tiagoluizpoli

View GitHub Profile
@Dante-101
Dante-101 / worker-shutdown.ts
Last active October 17, 2024 19:42
Gist for graceful shutdown of workers
gracefulClusterShutdown = (signal: NodeJS.Signals) => async () => {
if (this.shutdownInProgress)
return
this.shutdownInProgress = true
this.hasCleanWorkerExit = true
log.info(`Got ${signal} on ${this.processStr}. Graceful shutdown start at ${new Date().toISOString()}`)
try {
@Dante-101
Dante-101 / master-worker.ts
Last active October 17, 2024 19:42
Master process class managing workers
import * as cluster from 'cluster'
class Master {
private shutdownInProgress: boolean = false
private hasCleanWorkerExit: boolean = true
private processStr = `${cluster.isMaster ? "master" : "worker"} process ${process.pid}`
gracefulClusterShutdown = (signal: NodeJS.Signals) => async () => {
//defined in worker-shutdown.ts (https://gist.github.com/Dante-101/de2fbd5071bec0c0647f5c9fa1cfa179)