15

I'm thinking about making a Hubot clock-based notifier (think "It's 5, time to go home!" but less annoying and for a different reason). What's the best way to go about doing something like this in a Hubot script?

[edit] Here's an example using node-cron:

TIMEZONE = "America/New_York"
QUITTING_TIME = '0 0 17 * * 2-6' # M-F 5pm
ROOM = "Dev"

cronJob = require('cron').CronJob

module.exports = (robot) ->
        gohome = new cronJob QUITTING_TIME,
                ->
                        robot.messageRoom ROOM, "It's 5!  Go home!"
                null
                true
                TIMEZONE

dependencies:

"cron": "0.3.3",
"time": "0.8.2"
NickAldwin
  • 10,954
  • 11
  • 47
  • 65

2 Answers2

11

I would use node-cron. It's pretty flexible and fits your use case well.

https://github.com/ncb000gt/node-cron

Swift
  • 12,489
  • 5
  • 50
  • 78
7

I just stumbled upon hubot-cron.

This lets you schedule messages in hubot, but unfortunately doesn't persist jobs through restarts.

Ian
  • 9,208
  • 2
  • 31
  • 50
wrtsprt
  • 4,883
  • 4
  • 18
  • 28
  • 6
    Hi, I wrote hubot-cron. It saves your jobs in `robot.brain` which means it persists data through restarts as long as you use persistent data store such as Redis. – miyagawa Apr 01 '14 at 03:01