Class: Droonga::Processor

Inherits:
Object
  • Object
show all
Defined in:
lib/droonga/processor.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Processor

Returns a new instance of Processor.



23
24
25
26
27
28
# File 'lib/droonga/processor.rb', line 23

def initialize(options={})
  @options = options
  @database_name = @options[:database]
  @queue_name = @options[:options] || "DroongaQueue"
  @n_workers = @options[:n_workers] || 0
end

Instance Method Details

#process(envelope, synchronous = nil) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/droonga/processor.rb', line 44

def process(envelope, synchronous=nil)
  $log.trace("proessor: process: start")
  reply_to = envelope["replyTo"]
  command = envelope["type"]
  if @handler.processable?(command)
    $log.trace("proessor: process: handlable: #{command}")
    if synchronous.nil?
      synchronous = @handler.prefer_synchronous?(command)
    end
    if @n_workers.zero? or synchronous
      @handler.process(envelope)
    else
      @job_queue.push_message(envelope)
    end
  else
    $log.trace("proessor: process: ignore #{command}")
  end
  $log.trace("proessor: process: done")
end

#shutdownObject



37
38
39
40
41
42
# File 'lib/droonga/processor.rb', line 37

def shutdown
  $log.trace("processor: shutdown: start")
  @handler.shutdown
  @job_queue.close
  $log.trace("processor: shutdown: done")
end

#startObject



30
31
32
33
34
35
# File 'lib/droonga/processor.rb', line 30

def start
  Droonga::JobQueue.ensure_schema(@database_name,
                                  @queue_name)
  @job_queue = JobQueue.open(@database_name, @queue_name)
  @handler = Handler.new(@options)
end