I am trying to run a simple task to test out using resque and clockwork together.
My worker: app/workers/logger_helper.rb
class LoggerHelper
@queue = :log_queue
def self.before_perform
Rails.logger = Logger.new(File.open(Rails.root.join('log', 'resque.log')))
Rails.logger.level = Logger::DEBUG
end
def self.perform
time = Time.now
Rails.logger.info("testing #{time}")
end
end
My clock.rb file lib/clock.rb
require File.expand_path('../../config/boot', __FILE__)
require File.expand_path('../../config/environment', __FILE__)
require 'clockwork'
module Clockwork
handler do |job|
Resque.enqueue(job)
end
every(10.seconds, 'loggerhelper') {LoggerHelper}
end
Rake file:
require File.expand_path('../config/application', __FILE__)
Rails.application.load_tasks
require 'resque/tasks'
task(:default).clear
task default: [:spec]
task "resque:setup" => :environment do
QUEUE = '*'
end
First I run resque:setup Second I run clockwork lib/clockwork.rb
I get the following output in the terminal
INFO -- : Triggering 'loggerhelper'
INFO -- : Triggering 'loggerhelper'
...
But nothing writes to the log.
I've tried a combination of things but I don't see any output.
I did run
every(10.seconds, 'loggerhelper') {LoggerHelper.perform}
in the clock.rb file and it does work, but I didn't think that you were supposed to call deliver directly. Also I'm not sure if it's actually running off of the queue or just simply executing.
First the logger should be configured to:
I also simplified my clock.rb file although I think it works as it was originally:
Next I created a Proc file with the following:
If I run
in one terminal and then
in a second terminal it works! I hope this helps out.