Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

make a useful procline, and fix priority setup

  • Loading branch information...
commit d7b0410ce9918b687e5285bb997b0f4863af38b2 1 parent ab8bbc1
Brian Palmer codekitchen authored
Showing with 22 additions and 0 deletions.
  1. +3 −0  lib/delayed/pool.rb
  2. +19 −0 lib/delayed/worker.rb
3  lib/delayed/pool.rb
View
@@ -90,6 +90,9 @@ def spawn_all_workers
end
def spawn_worker(worker_config)
+ worker_config = worker_config.with_indifferent_access
+ worker_config[:max_priority] ||= nil
+ worker_config[:min_priority] ||= nil
worker = Delayed::PoolWorker.new(worker_config)
pid = fork do
ActiveRecord::Base.connection.reconnect!
19 lib/delayed/worker.rb
View
@@ -60,6 +60,12 @@ def exit?
@exit
end
+ def priority_string
+ min_priority = self.class.min_priority || 0
+ max_priority = self.class.max_priority
+ "priorities #{min_priority}..#{max_priority || "max"}"
+ end
+
def start(exit_when_queues_empty = false)
enable_gc_optimizations
@exit = false
@@ -69,20 +75,28 @@ def start(exit_when_queues_empty = false)
trap('TERM') { say 'Exiting...'; @exit = true }
trap('INT') { say 'Exiting...'; @exit = true }
+ waiting = false # avoid logging "waiting for queue" over and over
+
loop do
job = Delayed::Job.get_and_lock_next_available(name,
self.class.max_run_time,
@queue)
if job
+ waiting = false
+ start_time = Time.now
if @child = fork
+ procline "Forked #{@child} at #{start_time.to_i}"
Process.wait
else
+ procline "Processing #{job.name} since #{start_time.to_i}"
run(job)
exit! unless self.class.cant_fork
end
elsif exit_when_queues_empty
break
else
+ procline("Waiting for #{@queue} #{priority_string}") unless waiting
+ waiting = true
sleep(@@sleep_delay)
end
@@ -173,5 +187,10 @@ def fork
end
end
+ def procline(string)
+ $0 = "delayed_job: #{string}"
+ say "* #{string}"
+ end
+
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.