Help us understand the problem. What is going on with this article?

Hubotで定期タスクを動かす

More than 5 years have passed since last update.

Hubot上でcronを動かした時のメモ。
毎日、10時に朝会の連絡をするcronを設定してみます。

準備

node-cronが必要なのでインストールする。

% npm install cron --save

node-cronのドキュメントによると次のような記法になるみたいです。

var CronJob = require('cron').CronJob;
new CronJob('* * * * * *', function(), null, true, "Timezone");

Timezoneは指定しなくても問題ないが、使う場合はtimeモジュールが必要とのこと。

% npm install time --save

※ Herokuであれば環境変数の指定でTimezoneを変更できるので、そちらで指定してもいいっぽい。

% heroku config:add TZ=Asia/Tokyo

スクリプト作成

node-cronのドキュメントを参考に、coffeescriptを書く。

cron.coffee
cron = require('cron').CronJob

module.exports = (robot) ->
  new cron '0 0 10 * * 1-5', () =>
    robot.send {room: "#general"}, "朝会だお"
  , null, true, "Asia/Tokyo"
mats16
AWSでSolutions Architectをやっています。 投稿は、個人の意見であり、所属する企業や団体は関係ありません。お約束です。
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした