Class: PuppetX::Relay::Agent::Job::Dispatch

Inherits:
Base
  • Object
show all
Defined in:
lib/puppet_x/relay/agent/job/dispatch.rb

Instance Method Summary collapse

Methods inherited from Base

#to_job

Constructor Details

#initialize(backend, work, state_dir, exec_interval: nil) ⇒ Dispatch

Returns a new instance of Dispatch.

Parameters:



13
14
15
16
17
18
# File 'lib/puppet_x/relay/agent/job/dispatch.rb', line 13

def initialize(backend, work, state_dir, exec_interval: nil)
  @backend = backend
  @work = work
  @state_dir = state_dir
  @exec_interval = exec_interval || 15
end

Instance Method Details

#handle(_job) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/puppet_x/relay/agent/job/dispatch.rb', line 20

def handle(_job)
  Puppet.notice(_('Retrieving list of pending runs'))

  @backend.relay_api.get_runs
          .select { |run| run.state.status == :pending }
          .each do |run|
            task = Exec.new(@backend, run, File.join(@state_dir, run.id))
            @work.add(task, @exec_interval)
          end
rescue Net::HTTPError => e
  Puppet.warning(_('Failed to retrieve list of pending runs: %{e} (retrying)') % { e: e })
end