Class: Kommando::ScheduledCommandRunner

Inherits:
Object
  • Object
show all
Defined in:
lib/kommando/scheduled_command_runner.rb

Instance Method Summary collapse

Constructor Details

#initialize(coordinator, adapter, dependencies) ⇒ ScheduledCommandRunner

Returns a new instance of ScheduledCommandRunner.



3
4
5
6
7
# File 'lib/kommando/scheduled_command_runner.rb', line 3

def initialize(coordinator, adapter, dependencies)
  @coordinator = coordinator
  @adapter = adapter
  @dependencies = dependencies
end

Instance Method Details

#callObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/kommando/scheduled_command_runner.rb', line 9

def call
  fetched_command = false

  @adapter.fetch! do |command_name, parameters|
    unless self.class.const_defined?(command_name)
      raise Command::UnknownCommandError, "Unknown command `#{command_name}`"
    end

    fetched_command = true

    self.class.const_get(command_name).execute(@dependencies, parameters)
  end

  @coordinator.schedule_next_run(fetched_command ? 0 : 5)
end