Class: Logical::Naf::JobFetcher

Inherits:
Object
  • Object
show all
Includes:
Af::Application::SafeProxy
Defined in:
app/models/logical/naf/job_fetcher.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(machine) ⇒ JobFetcher

Returns a new instance of JobFetcher.



8
9
10
# File 'app/models/logical/naf/job_fetcher.rb', line 8

def initialize(machine)
  @machine = machine
end

Instance Attribute Details

#machineObject (readonly)

Returns the value of attribute machine.



6
7
8
# File 'app/models/logical/naf/job_fetcher.rb', line 6

def machine
  @machine
end

Instance Method Details

#fetch_next_jobObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/models/logical/naf/job_fetcher.rb', line 12

def fetch_next_job
  fetch_possible_jobs.each do |possible_job|
    running_job = nil
    ::Naf::HistoricalJob.lock_for_job_queue do
      running_job = start_job(possible_job)
    end

    if running_job.present?
      # Update tags
      running_job.remove_tags([::Naf::HistoricalJob::SYSTEM_TAGS[:pre_work]])
      running_job.add_tags([::Naf::HistoricalJob::SYSTEM_TAGS[:work]])

      # found a job
      parse_log_level(running_job)

      return running_job
    end
  end

  # no jobs found
  return nil
end