简体   繁体   中英

Rails clockwork display on log

I'm trying to learn how to use the gem clockwork . I'm just trying to test on my Mac and putting a line onto the development log. I have it set at 3 minutes just for testing.

I have the following in lib/clock.rb :

require 'clockwork'
module Clockwork
  handler do |job|
    puts "Running #{job} =================================="
  end
Clockwork.every(3.minutes, 'dailyjob')
end

Then I have lib/tasks/dailyjob.rb

class DailyJob
  def perform
    Rails.logger.info "Daily Job ========================================="
  end
end

I then start Clockworks via the console $ clockwork clock.rb . It starts up and every 3 minutes the console says:

Running dailyjob ==================================
I, [2014-03-04T11:03:32.084240 #66442]  INFO -- : Triggering 'dailyjob'

But, nothing shows up in the development.log file.

Thanks for the help!

Per docs , Clockwork will only write to STDOUT unless you configure it otherwise:

By default Clockwork logs to STDOUT. In case you prefer your own logger implementation you have to specify the logger configuration option. See example below.

Example from the docs is this:

module Clockwork
  configure do |config|
    config[:sleep_timeout] = 5
    config[:logger] = Logger.new(log_file_path)
    config[:tz] = 'EST'
    config[:max_threads] = 15
    config[:thread] = true
  end
end

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM