Class: God::Driver
- Inherits:
-
Object
- Object
- God::Driver
- Defined in:
- lib/god/driver.rb
Instance Attribute Summary collapse
-
#thread ⇒ Object
readonly
Returns the value of attribute thread.
Instance Method Summary collapse
-
#clear_events ⇒ Object
Clear all events for this Driver.
-
#initialize(task) ⇒ Driver
constructor
Instantiate a new Driver and start the scheduler loop to handle events
task
is the Task this Driver belongs to. -
#message(name, args = []) ⇒ Object
Queue an asynchronous message
name
is the Symbol name of the operationargs
is an optional Array of arguments. -
#schedule(condition, delay = condition.interval) ⇒ Object
Create and schedule a new DriverEvent
condition
is the Conditiondelay
is the number of seconds to delay (default: interval defined in condition).
Constructor Details
#initialize(task) ⇒ Driver
Instantiate a new Driver and start the scheduler loop to handle events
+task+ is the Task this Driver belongs to
Returns Driver
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/god/driver.rb', line 144 def initialize(task) @task = task @events = God::DriverEventQueue.new @thread = Thread.new do loop do begin @events.pop.handle_event rescue ThreadError => e # queue is empty break rescue Exception => e = format("Unhandled exception in driver loop - (%s): %s\n%s", e.class, e., e.backtrace.join("\n")) applog(nil, :fatal, ) end end end end |
Instance Attribute Details
#thread ⇒ Object (readonly)
Returns the value of attribute thread.
138 139 140 |
# File 'lib/god/driver.rb', line 138 def thread @thread end |
Instance Method Details
#clear_events ⇒ Object
Clear all events for this Driver
Returns nothing
167 168 169 |
# File 'lib/god/driver.rb', line 167 def clear_events @events.clear end |
#message(name, args = []) ⇒ Object
Queue an asynchronous message
+name+ is the Symbol name of the operation
+args+ is an optional Array of arguments
Returns nothing
176 177 178 |
# File 'lib/god/driver.rb', line 176 def (name, args = []) @events.push(DriverOperation.new(@task, name, args)) end |
#schedule(condition, delay = condition.interval) ⇒ Object
Create and schedule a new DriverEvent
+condition+ is the Condition
+delay+ is the number of seconds to delay (default: interval defined in condition)
Returns nothing
185 186 187 188 189 |
# File 'lib/god/driver.rb', line 185 def schedule(condition, delay = condition.interval) applog(nil, :debug, "driver schedule #{condition} in #{delay} seconds") @events.push(DriverEvent.new(delay, @task, condition)) end |