1- import { Container , Module } from 'noicejs' ;
1+ import { Container , Logger , Module } from 'noicejs' ;
22import * as sourceMapSupport from 'source-map-support' ;
33import * as yargs from 'yargs-parser' ;
44
@@ -15,7 +15,8 @@ import { ServiceModule } from 'src/module/ServiceModule';
1515import { TransformModule } from 'src/module/TransformModule' ;
1616import { BunyanLogger } from 'src/utils/BunyanLogger' ;
1717import { Schema } from 'src/utils/Schema' ;
18- import { signal , SIGNAL_STOP } from 'src/utils/Signal' ;
18+ import { signal , SIGNAL_RELOAD , SIGNAL_RESET , SIGNAL_STOP } from 'src/utils/Signal' ;
19+ import { ServiceLifecycle } from './Service' ;
1920
2021// main arguments
2122const MAIN_ARGS : yargs . Options = {
@@ -81,9 +82,26 @@ function createModules(botModule: BotModule, migrate: boolean) {
8182 return modules ;
8283}
8384
84- async function handleSignals ( bot : Bot ) {
85+ async function handleSignals ( bot : Bot , logger : Logger ) {
8586 await bot . start ( ) ;
86- await signal ( SIGNAL_STOP ) ;
87+ await bot . notify ( ServiceLifecycle . Start ) ;
88+
89+ const signals = [ SIGNAL_RELOAD , SIGNAL_RESET , SIGNAL_STOP ] ;
90+ let s = await signal ( ...signals ) ;
91+ while ( s !== SIGNAL_STOP ) {
92+ switch ( s ) {
93+ case SIGNAL_RELOAD :
94+ bot . notify ( ServiceLifecycle . Reload ) ;
95+ break ;
96+ case SIGNAL_RESET :
97+ bot . notify ( ServiceLifecycle . Reset ) ;
98+ break ;
99+ }
100+ s = await signal ( ...signals ) ;
101+ }
102+
103+ logger . info ( 'stop signal' ) ;
104+ await bot . notify ( ServiceLifecycle . Stop ) ;
87105 await bot . stop ( ) ;
88106}
89107
@@ -116,7 +134,7 @@ async function main(argv: Array<string>): Promise<number> {
116134 botModule . setBot ( bot ) ;
117135
118136 logger . info ( 'starting bot' ) ;
119- await handleSignals ( bot ) ;
137+ await handleSignals ( bot , logger ) ;
120138
121139 return STATUS_SUCCESS ;
122140}
0 commit comments