reload(cb) {
    this.reloadClusterInfo();
    // 只允许 online 和 exception状态时 执行 reload
    if (this.status !== 'online' && this.status !== 'exception') {
      return cb({
        code: 'SERVER_BUSY',
        messsage: 'server is busy now, status:' + this.status
      });
    }
    this.status = 'reload';
    // clean exception retry
    this.retryTimeoutId.forEach((timeout) => {
      clearTimeout(timeout);
    });

    let newWorkersNum = this.options.processorNum;
    // reset workers
    this.oldWorkers = this.workers;
    this.workers = {};
    // re-assign new sock files
    this.initTargetSocks(newWorkersNum);

    this.once('reload_failed', (err) => {
      cb(err);
    });

    this.once('reloaded', (config) => {
      config.reload = true;
      /**
       * tell master that new workers is ready,
       * master will start reload proxy to let
       * new request send to these new workers
       */
      this.emit('ready', config);
      this.status = 'reloaded';
      /**
       * update router in next-tick, and then wait until nginx reloaded
       */
      process.nextTick(() => {
        cb(null, (err) => {
          /**
           * here nginx reloaded, and callback to kill old workers
           */
          if (err) {
            log.error(FLAG_CHILD, `app_reload_failed : ${this.appId}`, err);
            let workers = this.workers;
            this.cleanWorkers(workers, () => {
              this.status = 'online';
            });
            this.workers = this.oldWorkers;
            this.oldWorkers = {};
          } else {
            log.info(FLAG_CHILD, `app_reload_success : ${this.appId} , now stop old workers`);
            this.cleanWorkers(this.oldWorkers, () => {
              this.status = 'online';
            });
            this.oldWorkers = {};
          }
        });
      });
    });
    log.info(FLAG_CHILD, `app_start_reload : ${this.appId} , old workers:`, Object.keys(this.oldWorkers));
    for (let i = 0; i < newWorkersNum; i++) {
      this._create();
    }
  }
/**
   * reload workers, only online status can enter this action
   */
reload workers, only online status can enter this action
reload workers only online status can enter this action
reload(cb) {
    this.reloadClusterInfo();
    if (this.status !== 'online' && this.status !== 'exception') {
      return cb({
        code: 'SERVER_BUSY',
        messsage: 'server is busy now, status:' + this.status
      });
    }
    this.status = 'reload';
    this.retryTimeoutId.forEach((timeout) => {
      clearTimeout(timeout);
    });
    let newWorkersNum = this.options.processorNum;
    this.oldWorkers = this.workers;
    this.workers = {};
    this.initTargetSocks(newWorkersNum);
    this.once('reload_failed', (err) => {
      cb(err);
    });
    this.once('reloaded', (config) => {
      config.reload = true;
      this.emit('ready', config);
      this.status = 'reloaded';
      process.nextTick(() => {
        cb(null, (err) => {
          if (err) {
            log.error(FLAG_CHILD, `app_reload_failed : ${this.appId}`, err);
            let workers = this.workers;
            this.cleanWorkers(workers, () => {
              this.status = 'online';
            });
            this.workers = this.oldWorkers;
            this.oldWorkers = {};
          } else {
            log.info(FLAG_CHILD, `app_reload_success : ${this.appId} , now stop old workers`);
            this.cleanWorkers(this.oldWorkers, () => {
              this.status = 'online';
            });
            this.oldWorkers = {};
          }
        });
      });
    });
    log.info(FLAG_CHILD, `app_start_reload : ${this.appId} , old workers:`, Object.keys(this.oldWorkers));
    for (let i = 0; i < newWorkersNum; i++) {
      this._create();
    }
  }
reload ( cb ) { this . reloadClusterInfo ( ) ; if ( this . status !== 'online' && this . status !== 'exception' ) { return cb ( { code : 'SERVER_BUSY' , messsage : 'server is busy now, status:' + this . status } ) ; } this . status = 'reload' ; this . retryTimeoutId . forEach ( ( timeout ) => { clearTimeout ( timeout ) ; } ) ; let newWorkersNum = this . options . processorNum ; this . oldWorkers = this . workers ; this . workers = { } ; this . initTargetSocks ( newWorkersNum ) ; this . once ( 'reload_failed' , ( err ) => { cb ( err ) ; } ) ; this . once ( 'reloaded' , ( config ) => { config . reload = true ; this . emit ( 'ready' , config ) ; this . status = 'reloaded' ; process . nextTick ( ( ) => { cb ( null , ( err ) => { if ( err ) { log . error ( FLAG_CHILD , ` ${ this . appId } ` , err ) ; let workers = this . workers ; this . cleanWorkers ( workers , ( ) => { this . status = 'online' ; } ) ; this . workers = this . oldWorkers ; this . oldWorkers = { } ; } else { log . info ( FLAG_CHILD , ` ${ this . appId } ` ) ; this . cleanWorkers ( this . oldWorkers , ( ) => { this . status = 'online' ; } ) ; this . oldWorkers = { } ; } } ) ; } ) ; } ) ; log . info ( FLAG_CHILD , ` ${ this . appId } ` , Object . keys ( this . oldWorkers ) ) ; for ( let i = 0 ; i < newWorkersNum ; i ++ ) { this . _create ( ) ; } }
reload workers, only online status can enter this action
reload workers only online status can enter this action
// 只允许 online 和 exception状态时 执行 reload // clean exception retry // reset workers // re-assign new sock files /**
       * tell master that new workers is ready,
       * master will start reload proxy to let
       * new request send to these new workers
       */ /**
       * update router in next-tick, and then wait until nginx reloaded
       */ /**
           * here nginx reloaded, and callback to kill old workers
           */