LoginSignup
0

More than 5 years have passed since last update.

clockworkの小さなサンプル手順メモ

Last updated at Posted at 2018-06-20

前提

  • Bundlerでインストール、管理
  • Railsアプリの中に入れた

メモ

インストール

Gemfileに追加

Gemfile
gem 'clockwork'

インストール

プロジェクト直下

$ bundle install ★インストール
$ bundle list ★確認

サンプル実装

  • 1分間に1回、日付時間のファイル名の空ファイルを作成する
lib/test-clockwork.rb
require "bundler"
Bundler.require

include Clockwork

every(1.minutes, 'test') do
  `touch \`date +%Y%m%d%H%M\``
end

実行

Ctrl+Cで中断しない限り、実行し続ける

コンソール
% bundle exec clockwork lib/test-clockwork.rb

Herokuでの実行

Procfileを準備。herokuにデプロイ
※上記サンプルだと touch だと実行した結果がわからないので、なにか別のものを用意する

Procfile

Procfile
worker: bundle exec clockwork lib/test-clockwork.rb

デプロイは省略

Worker起動

コンソール
% heroku ps ★ Workerが無かった場合は以下の通り
% heroku ps:scale worker=1
% heroku ps ★ 確認
% heroku ps:scale worker=0 ★ 止める

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0