Class: Ungulate::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/ungulate/server.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Server

Returns a new instance of Server.



5
6
7
8
9
# File 'lib/ungulate/server.rb', line 5

def initialize(options = {})
  @logger = options[:logger] || ::Logger.new($stdout)
  @job_processor = options[:job_processor]
  @queue = options[:queue]
end

Class Method Details

.configObject



12
13
14
# File 'lib/ungulate/server.rb', line 12

def config
  Ungulate.configuration
end

.runObject



16
17
18
19
20
21
# File 'lib/ungulate/server.rb', line 16

def run
  new(
    :job_processor => config.job_processor.call,
    :queue => config.queue.call
  ).run
end

Instance Method Details

#runObject



24
25
26
27
28
29
30
31
32
33
# File 'lib/ungulate/server.rb', line 24

def run
  @logger.info "Checking for job on #{@queue.name}"
  message = @queue.receive

  if message
    success = @job_processor.process(message.to_s)
    message.delete
    success
  end
end