【问题标题】:How to use Hubot and node-cron with the IRC adapter如何通过 IRC 适配器使用 Hubot 和 node-cron
【发布时间】:2014-07-07 16:00:12
【问题描述】:

我无法正确设置 Hubot 和 node-cron 以在我的 IRC 频道中执行任务。

此页面显示了我最初是如何设置我的代码的: https://leanpub.com/automation-and-monitoring-with-hubot/read#leanpub-auto-periodic-task-execution

这里是 node-cron 的链接: https://github.com/ncb000gt/node-cron

我认为我在使用 Hubot 的 IRC 适配器时遇到了问题,但我不确定。欢迎任何建议和代码示例。

这是我最终测试的地方:

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!"

或来自 Leanpub 的示例

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

Hubot 运行后的 cron 作业设置工作正常:

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

再次感谢大家!

【问题讨论】:

  • 要检查是否是 irc 适配器的问题,请尝试在您的 testFunction 中执行 console.log 并查看它是否出现在日志中。如果是这样,但房间中没有出现消息,这可能意味着您使用了错误的房间名称,或者messageRoom 实现没有按预期工作。另外,robot.send 也不起作用,不清楚 cron 触发该功能时将消息发送到哪里。

标签: node.js coffeescript cron irc hubot


【解决方案1】:

所以我们最终使用了稍微不同的格式来启动和运行它。对于我们的使用,我们排除了时区信息,但它也适用。

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

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

如果有人使用更接近示例的代码运行此操作,请随时回答。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-02-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多