plugin-contrib icon indicating copy to clipboard operation
plugin-contrib copied to clipboard

NewPlugin: Crontab

Open huan opened this issue 5 years ago • 0 comments

Like the following code from our Friday BOT demonstrated: (original author: @qhduan )

import cron from 'node-cron'

interface CRONConfig {
  time: string,
  reply: string
}

const CRON_CONFIG: CRONConfig[] = [
  {
    reply: '星期一了,如果主席还没发活动总结的话要注意了',
    /**
     * 定时任务
     *     ┌─────────────── second (optional)
     *     │ ┌───────────── minute
     *     │ │ ┌─────────── hour
     *     │ │ │  ┌──────── day of month
     *     │ │ │  │ ┌────── month
     *     │ │ │  │ │ ┌──── day of week
     *     │ │ │  │ │ │
     *     │ │ │  │ │ │
     *     * * *  * * *      // */
    time: '0 0 19 * * 1',
  },
]

/**
 * TODO: Huan(202006)
 */
export async function crontab () {
  for (const cronConfig of CRON_CONFIG) {
    cron.schedule(cronConfig.time, async () => {
      // await Chatops.instance().say(cronConfig.reply)
    })
  }
}

See:

  • https://godoc.org/github.com/robfig/cron#hdr-CRON_Expression_Format

huan avatar Aug 01 '20 07:08 huan