Class: Gandalf::Optimus_Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/optimus-runner.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Optimus_Runner

Returns a new instance of Optimus_Runner.



10
11
12
13
14
15
16
17
# File 'lib/optimus-runner.rb', line 10

def initialize(options)
  @options = options
  @optimus_runner_sm = OptimusRunnerSM.new
  @scheduler = Rufus::Scheduler.new
  logger = Logger.new(STDOUT)
  logger.level = Logger::WARN
  logger.info "Starting Optimus runner..."
end

Instance Attribute Details

#optimus_runner_smObject (readonly)

Returns the value of attribute optimus_runner_sm.



8
9
10
# File 'lib/optimus-runner.rb', line 8

def optimus_runner_sm
  @optimus_runner_sm
end

#optionsObject (readonly)

Returns the value of attribute options.



8
9
10
# File 'lib/optimus-runner.rb', line 8

def options
  @options
end

#schedulerObject (readonly)

Returns the value of attribute scheduler.



8
9
10
# File 'lib/optimus-runner.rb', line 8

def scheduler
  @scheduler
end

Instance Method Details

#run!Object



20
21
22
23
24
25
26
27
28
29
# File 'lib/optimus-runner.rb', line 20

def run!
  @scheduler.interval '5s', :first_in => 0.1 do
    logger.info "Is Optimus runner idle? #{@optimus_runner_sm.idle?}"
    @optimus_runner_sm.create if @optimus_runner_sm.idle?
    @optimus_runner_sm.add if @optimus_runner_sm.new_device_added?
    @optimus_runner_sm.remove if @optimus_runner_sm.device_removed?
    @optimus_runner_sm.restart if @optimus_runner_sm.session_terminated?
  end
  @scheduler.join
end