* Set up signals that are captured to shutdown the application
()
| 584 | * Set up signals that are captured to shutdown the application |
| 585 | */ |
| 586 | protected setupShutdown() { |
| 587 | if (this._signalListener != null) { |
| 588 | this.registerSignalListener(); |
| 589 | return this._signalListener; |
| 590 | } |
| 591 | const gracePeriod = this._shutdownOptions.gracePeriod; |
| 592 | this._signalListener = async (signal: string) => { |
| 593 | const kill = () => { |
| 594 | this.removeSignalListener(); |
| 595 | process.kill(process.pid, signal); |
| 596 | }; |
| 597 | debugShutdown( |
| 598 | '[%s] Signal %s received for process %d', |
| 599 | this.name, |
| 600 | signal, |
| 601 | process.pid, |
| 602 | ); |
| 603 | if (!this._isShuttingDown) { |
| 604 | this._isShuttingDown = true; |
| 605 | let timer; |
| 606 | if (typeof gracePeriod === 'number' && !isNaN(gracePeriod)) { |
| 607 | timer = setTimeout(kill, gracePeriod); |
| 608 | } |
| 609 | try { |
| 610 | await this.stop(); |
| 611 | } finally { |
| 612 | if (timer != null) clearTimeout(timer); |
| 613 | kill(); |
| 614 | } |
| 615 | } |
| 616 | }; |
| 617 | this.registerSignalListener(); |
| 618 | return this._signalListener; |
| 619 | } |
| 620 | |
| 621 | private registerSignalListener() { |
| 622 | const {signals = []} = this._shutdownOptions; |
no test coverage detected