Skip to content

Commit

Permalink
added log_queries option, which if set to false will silence the db q…
Browse files Browse the repository at this point in the history
…ueries from showing up in the log every 5 seconds
  • Loading branch information
iamnader committed Oct 28, 2010
1 parent aba9905 commit 2c42671
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.textile
Expand Up @@ -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
Expand Down
11 changes: 9 additions & 2 deletions lib/delayed/worker.rb
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 2c42671

Please sign in to comment.