Parent

Files

Class/Module Index [+]

Quicksearch

God::Driver

The Driver class is responsible for scheduling all of the events for a given Task.

Attributes

thread[R]

The Thread running the driver loop.

Public Class Methods

new(task) click to toggle source

Instantiate a new Driver and start the scheduler loop to handle events.

task - The Task this Driver belongs to.

# File lib/god/driver.rb, line 174
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 Object => e
        message = format("Unhandled exception in driver loop - (%s): %s\n%s",
                         e.class, e.message, e.backtrace.join("\n"))
        applog(nil, :fatal, message)
      end
    end
  end
end

Public Instance Methods

clear_events() click to toggle source

Clear all events for this Driver.

Returns nothing.

# File lib/god/driver.rb, line 204
def clear_events
  @events.clear
end
in_driver_context?() click to toggle source

Check if we're in the driver context.

Returns true if in driver thread, false if not.

# File lib/god/driver.rb, line 197
def in_driver_context?
  Thread.current == @thread
end
message(name, args = []) click to toggle source

Queue an asynchronous message.

name - The Symbol name of the operation. args - An optional Array of arguments.

Returns nothing.

# File lib/god/driver.rb, line 221
def message(name, args = [])
  @events.push(DriverOperation.new(@task, name, args))
end
schedule(condition, delay = condition.interval) click to toggle source

Create and schedule a new DriverEvent.

condition - The Condition. delay - The Numeric number of seconds to delay (default: interval

defined in condition).

Returns nothing.

# File lib/god/driver.rb, line 232
def schedule(condition, delay = condition.interval)
  applog(nil, :debug, "driver schedule #{condition} in #{delay} seconds")

  @events.push(DriverEvent.new(delay, @task, condition))
end
shutdown() click to toggle source

Shutdown the DriverEventQueue threads.

Returns nothing.

# File lib/god/driver.rb, line 211
def shutdown
  @events.shutdown
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.