Domanda

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!

È stato utile?

Soluzione

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
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top