简体   繁体   中英

How to use Hubot and node-cron with the IRC adapter

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!

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM