Class: Refinery::Daemon

Inherits:
Thread
  • Object
show all
Includes:
Configurable, Loggable, Queueable, Utilities
Defined in:
lib/refinery/daemon.rb

Overview

A daemon provides a thread to run workers in.

Constant Summary collapse

RUNNING =
'running'
STOPPED =
'stopped'

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Queueable

#queue, #with_queue

Methods included from Configurable

#config, #config=

Methods included from Loggable

#logger

Methods included from Utilities

#camelize, #decode_message, #encode_message, #host_info

Constructor Details

#initialize(processor, name, queue_prefix = '', settings = {}) ⇒ Daemon

Initialize the daemon.

  • processor: The processor instance

  • name: The processor name

  • waiting_queue: The waiting queue that provides messages to be processed

  • error_queue: The queue where errors are posted.

  • done_queue: The queue for messages that have been processed.

  • settings: The settings hash from the config.

The settings hash may contain the following options:

  • visibility: The time in seconds that the message is hidden

in the queue.



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/refinery/daemon.rb', line 52

def initialize(processor, name, queue_prefix='', settings={})
  logger.debug "Starting daemon"
  
  @processor = processor
  @name = name
  @settings = settings
  
  queue_name = settings['queue'] || name
  queue_name = "#{queue_prefix}#{queue_name}"
  logger.debug "Using queue #{queue_name}"
  @queue_name = queue_name
  
  super do
    begin
      execute
    rescue Exception => e
      logger.error e
    end
  end
end

Instance Attribute Details

#nameObject (readonly)

The name of the daemon



13
14
15
# File 'lib/refinery/daemon.rb', line 13

def name
  @name
end

#queue_nameObject (readonly)

The base queue name



17
18
19
# File 'lib/refinery/daemon.rb', line 17

def queue_name
  @queue_name
end

#settingsObject (readonly)

The settings for the daemon



15
16
17
# File 'lib/refinery/daemon.rb', line 15

def settings
  @settings
end

Instance Method Details

#running?Boolean

Return true if the daemon state is running.

Returns:

  • (Boolean)


36
37
38
# File 'lib/refinery/daemon.rb', line 36

def running?
  state == RUNNING
end

#state=(state) ⇒ Object

Set the daemon state.



30
31
32
# File 'lib/refinery/daemon.rb', line 30

def state=(state)
  @state = state
end

#stopObject

Stop the daemon



20
21
22
# File 'lib/refinery/daemon.rb', line 20

def stop
  self.state = STOPPED
end