環境
ruby 2.2.3
rails 4.2.5.1
Ruby on Rails で clockwork で行き詰ってます。
以下のプログラムで、モデルArtcleのデータを取得できません。
ruby
1require 'clockwork' 2 3require File.expand_path('../config/boot', __FILE__) 4require File.expand_path('../config/environment', __FILE__) 5 6module Clockwork 7 8 handler do |job| 9 user_id = '001' 10 len = Article.where(user_id: user_id).length 11 puts "user_idが001のデータの数は"+len.to_s 12 end 13 14every(1.minutes, 'test') 15 16end 17
実際にデータベースにはuser_idが001のデータの数は10あるのですが、
このプログラムを動かすと以下のようにuser_id が “001”の数がゼロと表示されます。
$ bundle exec clockwork clockwork.rb I, [2017-02-09T23:04:10.387361 #8340] INFO -- : Starting clock for 1 events: [ test ] I, [2017-02-09T23:04:10.387430 #8340] INFO -- : Triggering 'test' user_idが001のデータの数は0
以上、ご教授お願いいたします。
あなたの回答
tips
プレビュー