lib/sequel/worker.rb in sequel-0.4.4.1 vs lib/sequel/worker.rb in sequel-0.4.4.2
- old
+ new
@@ -1,11 +1,11 @@
-require 'thread'
+require "thread"
module Sequel
+
class Worker < Thread
- class WorkerStopError < RuntimeError; end
-
+
attr_reader :queue
attr_reader :errors
def initialize(db = nil)
@queue = Queue.new
@@ -16,11 +16,11 @@
db ? super {db.transaction {t.work}} : super {t.work}
end
def work
loop {next_job}
- rescue WorkerStopError # signals the worker thread to stop
+ rescue Sequel::Error::WorkerStop # signals the worker thread to stop
ensure
rollback! if @transaction && !@errors.empty?
end
def busy?
@@ -36,22 +36,23 @@
def join
while busy?
sleep 0.1
end
- self.raise WorkerStopError
+ self.raise Error::WorkerStop
super
end
private
def next_job
@cur = @queue.pop
@cur.call
- rescue WorkerStopError => e
+ rescue Error::WorkerStop => e
raise e
rescue Exception => e
@errors << e
ensure
@cur = nil
end
end
-end
\ No newline at end of file
+
+end