Permalink
Browse files

Allow thread pool threads to be interrupted

  • Loading branch information...
1 parent f4d43fe commit 087b0913dfc3d6ea6491215145077221277b9158 Seth Morabito committed Oct 29, 2008
Showing with 12 additions and 4 deletions.
  1. +12 −4 server/lib/bdrb_thread_pool.rb
@@ -1,4 +1,7 @@
module BackgrounDRb
+
+ class InterruptedException < RuntimeError ; end
+
class WorkData
attr_accessor :args,:block,:job_method,:persistent_job_id,:job_key
def initialize(args,job_key,job_method,persistent_job_id)
@@ -54,10 +57,15 @@ def add_thread
Thread.current[:job_key] = nil
Thread.current[:persistent_job_id] = nil
while true
- task = @work_queue.pop
- Thread.current[:job_key] = task.job_key
- Thread.current[:persistent_job_id] = task.persistent_job_id
- block_result = run_task(task)
+ begin
+ task = @work_queue.pop
+ Thread.current[:job_key] = task.job_key
+ Thread.current[:persistent_job_id] = task.persistent_job_id
+ block_result = run_task(task)
+ rescue InterruptedException
+ # Allow threads to be interrupted, then continue
+ next
+ end
end
end
end

0 comments on commit 087b091

Please sign in to comment.