Class: Refinery::Daemon
- Inherits:
-
Thread
- Object
- Thread
- Refinery::Daemon
- 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
-
#name ⇒ Object
readonly
The name of the daemon.
-
#queue_name ⇒ Object
readonly
The base queue name.
-
#settings ⇒ Object
readonly
The settings for the daemon.
Instance Method Summary collapse
-
#initialize(processor, name, queue_prefix = '', settings = {}) ⇒ Daemon
constructor
Initialize the daemon.
-
#running? ⇒ Boolean
Return true if the daemon state is running.
-
#state=(state) ⇒ Object
Set the daemon state.
-
#stop ⇒ Object
Stop the daemon.
Methods included from Queueable
Methods included from Configurable
Methods included from Loggable
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
#name ⇒ Object (readonly)
The name of the daemon
13 14 15 |
# File 'lib/refinery/daemon.rb', line 13 def name @name end |
#queue_name ⇒ Object (readonly)
The base queue name
17 18 19 |
# File 'lib/refinery/daemon.rb', line 17 def queue_name @queue_name end |
#settings ⇒ Object (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.
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 |
#stop ⇒ Object
Stop the daemon
20 21 22 |
# File 'lib/refinery/daemon.rb', line 20 def stop self.state = STOPPED end |