Permalink
Browse files

code review feedback from Myron

  • Loading branch information...
1 parent ff33a61 commit 130493aafe59d5ccd6a05c5bdb09ee825b0e30f2 Patrick Roby committed May 30, 2012
Showing with 17 additions and 27 deletions.
  1. +10 −12 lib/qless/worker.rb
  2. +7 −15 spec/integration/worker_spec.rb
View
22 lib/qless/worker.rb
@@ -33,7 +33,7 @@ def initialize(client, job_reserver, options = {})
# - INTERVAL=3.2
# - VERBOSE=true (to enable logging)
# - VVERBOSE=true (to enable very verbose logging)
- # - run_as_single_process=true (false will fork children to do work, true will keep it single process)
+ # - RUN_AS_SINGLE_PROCESS=true (false will fork children to do work, true will keep it single process)
# This is designed to be called from a rake task
def self.start
client = Qless::Client.new
@@ -72,20 +72,18 @@ def work(interval = 5.0)
log "got: #{job.inspect}"
if run_as_single_process
- # We're in the child process
+ # We're staying in the same process
procline "Singe processing #{job.description}"
perform(job)
+ elsif @child = fork
+ # We're in the parent process
+ procline "Forked #{@child} for #{job.description}"
+ Process.wait(@child)
else
- if @child = fork
- # We're in the parent process
- procline "Forked #{@child} for #{job.description}"
- Process.wait(@child)
- else
- # We're in the child process
- procline "Processing #{job.description}"
- perform(job)
- exit!
- end
+ # We're in the child process
+ procline "Processing #{job.description}"
+ perform(job)
+ exit!
end
end
end
View
22 spec/integration/worker_spec.rb
@@ -11,27 +11,19 @@ def self.perform(job)
end
describe "Worker integration", :integration do
- def initialize_and_start_worker(run_as_single_process)
- if run_as_single_process
- unless @child = fork
- start_worker(run_as_single_process)
- end
- else
- start_worker(run_as_single_process)
- end
- end
-
def start_worker(run_as_single_process)
- with_env_vars 'REDIS_URL' => redis_url, 'QUEUE' => 'main', 'INTERVAL' => '0.0001', 'RUN_AS_SINGLE_PROCESS ' => run_as_single_process do
- Qless::Worker.start
- exit!
+ unless @child = fork
+ with_env_vars 'REDIS_URL' => redis_url, 'QUEUE' => 'main', 'INTERVAL' => '0.0001', 'RUN_AS_SINGLE_PROCESS' => run_as_single_process do
+ Qless::Worker.start
+ exit!
+ end
end
end
shared_examples_for 'a running worker' do |run_as_single_process|
it 'can start a worker and then shut it down' do
words = %w{foo bar howdy}
- initialize_and_start_worker(run_as_single_process)
+ start_worker(run_as_single_process)
queue = client.queues["main"]
words.each do |word|
@@ -46,7 +38,7 @@ def start_worker(run_as_single_process)
end
end
- it_behaves_like 'a running worker', '0'
+ it_behaves_like 'a running worker'
it_behaves_like 'a running worker', '1'
end

0 comments on commit 130493a

Please sign in to comment.