4

I've been unable to properly setup Hubot and node-cron to execute tasks within my IRC channels.

This page shows how I initially setup my code: https://leanpub.com/automation-and-monitoring-with-hubot/read#leanpub-auto-periodic-task-execution

Here is the link to node-cron: https://github.com/ncb000gt/node-cron

I'm thinking I'm running into an issue with Hubot's IRC adapter, but I'm not sure. Any advice and code examples would be welcome.

Here is where I've ended up in testing:

module.exports = (robot) ->
  cronJob = require('cron').CronJob
  tz = 'America/Minneapolis'
  new cronJob('30 * * * * *', testFunction, true, tz)
  room = '#support' #not used in this case

testFunction = ->
  robot.send "I work!"

or per example from Leanpub

testFunction = ->
  robot.messageRoom room "I work!"

cron jobs setup after Hubot is running work fine:

Hubot new job "<crontab format>" <message> - Schedule a cron job to say something

Thank you again, all!

Chad L
  • 71
  • 5
  • 1
    To check if it's an issue of irc adapter, try doing a `console.log` in your `testFunction` and see if it appears in logs. If it does, but message does not appear in room, it could mean that you are using wrong room name, or `messageRoom` implementation does not work as expected. Also, `robot.send` will not work, it's not clear where to send the message when cron triggered the function. – Spajus May 20 '14 at 04:06

1 Answers1

3

So we ended up using a slightly different format to get this up and running. For our uses, we excluded the time zone info, but it works with it as well.

module.exports = (robot) ->
  cronJob = require('cron').CronJob
  new cronJob('0 */1 * * * *', everyMinute(robot), null, true)

everyMinute = (robot) ->
  -> robot.messageRoom '#billing', 'hey brah!'

If anyone has this running with code closer to the examples, feel free to answer.

Chad L
  • 71
  • 5