Skip to content

Commit

Permalink
handle more exceptions and add more testcases
Browse files Browse the repository at this point in the history
  • Loading branch information
gnufied committed Jul 12, 2008
1 parent 8ac2d17 commit e3c7bd1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
26 changes: 18 additions & 8 deletions server/lib/meta_worker.rb
Expand Up @@ -196,10 +196,15 @@ def process_request(p_data)

Thread.current[:job_key] = user_input[:job_key]

if called_method_arity != 0
result = self.send(user_input[:worker_method],*user_input[:arg])
else
result = self.send(user_input[:worker_method])
begin
if called_method_arity != 0
result = self.send(user_input[:worker_method],*user_input[:arg])
else
result = self.send(user_input[:worker_method])
end
rescue
logger.info($!.to_s)
logger.info($!.backtrace.join("\n"))
end

if p_data[:result]
Expand Down Expand Up @@ -274,10 +279,15 @@ def check_for_enqueued_tasks
Thread.current[:job_key] = task[:job_key]
called_method_arity = self.method(task.worker_method).arity
args = load_data(task.args)
if called_method_arity != 0
self.send(task.worker_method,*args)
else
self.send(task.worker_method)
begin
if called_method_arity != 0
self.send(task.worker_method,*args)
else
self.send(task.worker_method)
end
rescue
logger.info($!.to_s)
logger.info($!.backtrace.join("\n"))
end
else
task.release_job
Expand Down
4 changes: 2 additions & 2 deletions test/server/test_meta_worker.rb
Expand Up @@ -247,7 +247,7 @@ def ivar(var)
mocked_task = mock()
mocked_task.expects(:worker_method).returns(:barbar).times(3)
mocked_task.expects(:args).returns(Marshal.dump("hello"))
mocked_task.expects(:[]).returns(1)
mocked_task.expects(:[]).returns(1).times(2)
@meta_worker.expects(:barbar).with("hello").returns(true)
BdrbJobQueue.expects(:find_next).with("queue_worker").returns(mocked_task)
@meta_worker.check_for_enqueued_tasks
Expand All @@ -256,7 +256,7 @@ def ivar(var)
specify "should run enqueued tasks without arguments if they are there in the queue" do
@meta_worker = QueueWorker.start_worker
mocked_task = mock()
mocked_task.expects(:[]).returns(1)
mocked_task.expects(:[]).returns(1).times(2)
mocked_task.expects(:worker_method).returns(:barbar).times(3)
mocked_task.expects(:args).returns(nil)
@meta_worker.expects(:barbar)
Expand Down

0 comments on commit e3c7bd1

Please sign in to comment.