Class: Wakame::StatusDB::WorkerThread
- Inherits:
-
Object
- Object
- Wakame::StatusDB::WorkerThread
- Defined in:
- lib/wakame/status_db.rb
Class Method Summary collapse
Class Method Details
.init ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/wakame/status_db.rb', line 67 def self.init @proceed_reqs = 0 if @thread.nil? @thread = Thread.new { while blk = queue.deq Wakame.log.debug("#{self}: Queued Jobs: #{queue.size}") if queue.size > 0 begin Wakame::Models::ObjectStore.db.transaction { blk.call } rescue => e Wakame.log.error("#{self.class}: #{e}") Wakame.log.error(e) end @proceed_reqs += 1 end } end end |
.queue ⇒ Object
59 60 61 |
# File 'lib/wakame/status_db.rb', line 59 def self.queue @queue ||= ::Queue.new end |
.terminate ⇒ Object
88 89 90 91 92 93 94 |
# File 'lib/wakame/status_db.rb', line 88 def self.terminate if self.queue.size > 0 Wakame.log.warn("#{self.class}: #{self.class.queue.size} of queued reqs are going to be ignored to shutdown the worker thread.") self.queue.clear end self.worker_thread.kill if !self.worker_thread.nil? && self.worker_thread.alive? end |
.worker_thread ⇒ Object
63 64 65 |
# File 'lib/wakame/status_db.rb', line 63 def self.worker_thread @thread end |