node regular tasks

1. Create a schedule file

2. The following code example

const Subscription = the require ( ' Egg ' ) .Subscription;
 const Report the require = ( ' ../utils/report ' ); 

class the SendMail the extends Subscription {
   // set the timing of tasks performed by the schedule property arranged at intervals 
  static  GET schedule ( ) {
     return {
       // interval the: 'IH', // . 1 hour interval 
      type: ' worker ' , // machine only a worker performs each task this timing
       // immediate: to true, // the app ready to run immediately time (on-line comment out) 
      the cron: '? 0 30 10 * MON ' , // Monday morning 10:00
       // cron:' 0 * / 1 * * *? ', // once every 1 minute 
      disable: The require ( ' os ' !) .Hostname () = = ' LBS-dev-monitor011015250024.center.na62 ' , 
    }; 
  } 

  // Subscribe is a function of the real operation timing of the task execution 
  * Subscribe () {
     const {Logger, Diamond} = the this .ctx; 
    logger.info ( ' Schedule Check Monitor ' );
     const monitorData = the yield diamond.getConfig ( 'monitor', 'lbs');
    logger.info('get cc from diamond');

    const feedbackMailCC = JSON.parse(monitorData).feedbackMailCC;
    yield report(new Date().getTime(), 1,feedbackMailCC, logger);
  }
}

module.exports = SendMail;

 

Guess you like

Origin www.cnblogs.com/kaiqinzhang/p/11884203.html