Skip to content
Browse files

added log_queries option, which if set to false will silence the db q…

…ueries from showing up in the log every 5 seconds
  • Loading branch information...
1 parent aba9905 commit 2c42671ffd0e51775f20b4c7c9e8d215af417bd3 @iamnader iamnader committed Oct 28, 2010
Showing with 10 additions and 2 deletions.
  1. +1 −0 README.textile
  2. +9 −2 lib/delayed/worker.rb
View
1 README.textile
@@ -223,6 +223,7 @@ Delayed::Worker.destroy_failed_jobs = false
Delayed::Worker.sleep_delay = 60
Delayed::Worker.max_attempts = 3
Delayed::Worker.max_run_time = 5.minutes
+Delayed::Worker.loq_queries = false # if you don't want the sql query to show up in your log every 5 secs
</pre>
h3. Cleaning up
View
11 lib/delayed/worker.rb
@@ -6,11 +6,12 @@
module Delayed
class Worker
- cattr_accessor :min_priority, :max_priority, :max_attempts, :max_run_time, :default_priority, :sleep_delay, :logger
+ cattr_accessor :min_priority, :max_priority, :max_attempts, :max_run_time, :default_priority, :sleep_delay, :logger, :log_queries
self.sleep_delay = 5
self.max_attempts = 25
self.max_run_time = 4.hours
self.default_priority = 0
+ self.log_queries = true
# By default failed jobs are destroyed after too many attempts. If you want to keep them around
# (perhaps to inspect the reason for the failure), set this to false.
@@ -163,7 +164,13 @@ def reserve_and_run_one_job
# We get up to 5 jobs from the db. In case we cannot get exclusive access to a job we try the next.
# this leads to a more even distribution of jobs across the worker processes
- job = Delayed::Job.find_available(name, 5, self.class.max_run_time).detect do |job|
+ if self.class.log_queries || !logger
+ available_jobs = find_available_jobs
+ else
+ logger.silence { available_jobs = find_available_jobs}
+ end
+
+ job = available_jobs.detect do |job|
if job.lock_exclusively!(self.class.max_run_time, name)
say "acquired lock on #{job.name}"
true

0 comments on commit 2c42671

Please sign in to comment.
Something went wrong with that request. Please try again.