railsで定期処理をさせるcronのようなgem、clockwork(1.2.0)
を使用しています。clockworkからrakeコマンドを実行させているのですが、rakeコマンドに記述したputsがコンソールに出力されません。コンソールから直接rakeを実行した場合は、ちゃんと出力されています。clockworkからrakeコマンドを実行させるにはどうすればいいでしょうか?clockwork自体は正常に稼働しています。
ご回答、よろしくお願い致します。
環境
ruby
1# lib/task/greeting.rake 2namespace :greeting do 3 desc "Say hello world" 4 task :hello do 5 puts "hello world" 6 end 7end
ruby
1# config/clock.rb 2require 'clockwork' 3require File.expand_path('../boot', __FILE__) 4require File.expand_path('../environment', __FILE__) 5 6module Clockwork 7 every(1.minute, 'one_minute') do 8 puts "start" 9 `rake greeting:hello` 10 puts "finish" 11 end 12end
% sw_vers ProductName: Mac OS X ProductVersion: 10.10.5 BuildVersion: 14F27 % rails about About your application's environment Rails version 4.2.3 Ruby version 2.2.2-p95 (x86_64-darwin14) RubyGems version 2.4.5 Rack version 1.6.4 JavaScript Runtime Node.js (V8) Middleware Rack::Sendfile, ActionDispatch::Static, Rack::Lock, #<ActiveSupport::Cache::Strategy::LocalCache::Middleware:0x007f9f8c18e498>, Rack::Runtime, Rack::MethodOverride, ActionDispatch::RequestId, Rails::Rack::Logger, ActionDispatch::ShowExceptions, WebConsole::Middleware, ActionDispatch::DebugExceptions, ActionDispatch::RemoteIp, ActionDispatch::Reloader, ActionDispatch::Callbacks, ActiveRecord::Migration::CheckPending, ActiveRecord::ConnectionAdapters::ConnectionManagement, ActiveRecord::QueryCache, ActionDispatch::Cookies, ActionDispatch::Session::CookieStore, ActionDispatch::Flash, ActionDispatch::ParamsParser, Rack::Head, Rack::ConditionalGet, Rack::ETag Application root /Users/myname/myrepository/rails_sample/blog Environment development Database adapter sqlite3 Database schema version 20151005015619
※ bundleのインストール先はvendor/bundle
に。rubyのバージョン管理はrbenvを使用しています。
コンソールの実行結果
% rake greeting:hello hello world % bundle exec clockwork config/clock.rb I, [2015-10-06T11:00:31.976341 #11613] INFO -- : Starting clock for 1 events: [ one_minute ] I, [2015-10-06T11:00:31.976416 #11613] INFO -- : Triggering 'one_minute' start finish
あなたの回答
tips
プレビュー