Class: Wakame::StatusDB::WorkerThread

Inherits:
Object
  • Object
show all
Defined in:
lib/wakame/status_db.rb

Class Method Summary collapse

Class Method Details

.initObject



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/wakame/status_db.rb', line 53

def self.init
  @proceed_reqs = 0

  if @thread.nil?
    @thread = Thread.new {
      while blk = queue.deq
        begin
          blk.call
        rescue => e
          Wakame.log.error("#{self.class}: #{e}")
          Wakame.log.error(e)
        end
        @proceed_reqs += 1
      end
    }
  end
end

.queueObject



45
46
47
# File 'lib/wakame/status_db.rb', line 45

def self.queue
  @queue ||= ::Queue.new
end

.terminateObject



71
72
73
74
75
76
77
# File 'lib/wakame/status_db.rb', line 71

def self.terminate
  if self.queue.size > 0
    Wakame.log.warn("#{self.class}: #{self.class.queue.size} of non-processed 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_threadObject



49
50
51
# File 'lib/wakame/status_db.rb', line 49

def self.worker_thread
  @thread 
end