Class: Marty::Diagnostic::DelayedJobVersion

Inherits:
Base show all
Defined in:
lib/marty/diagnostic/delayed_job_version.rb

Class Method Summary collapse

Methods inherited from Base

get_final_attrs, get_struct_attrs, make_hash, make_openstruct, mcfly_pt

Methods inherited from ActiveRecord::Base

joins, old_joins

Class Method Details

.generateObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/marty/diagnostic/delayed_job_version.rb', line 11

def self.generate
  raise 'DelayedJob cannot be called with local scope.' if scope == 'local'

  raise 'DELAYED_VER environment variable has not been initialized.' if
    ENV['DELAYED_VER'].nil?

  total_workers = Node.get_target_connections('delayed').count

  raise 'No delayed jobs are running.' if total_workers.zero?

  # we will only iterate by half of the total delayed workers to avoid
  # excess use of delayed job time
  total_workers = (total_workers / 2).zero? ? 1 : total_workers / 2

  d_engine = Marty::ScriptSet.new.get_engine('Diagnostics')
  res = d_engine.
          evaluate('VersionDelay', 'result', 'count' => total_workers - 1)

  # merge results, remove duplicates, and construct "aggregate" object
  res.each_with_object({}) do |r, hash|
    hash[r[0]] ||= []
    hash[r[0]] << r[1]
  end.map do |node, result|
    versions = result.uniq
    status = versions.count == 1 && versions[0] == ENV['DELAYED_VER']

    { node => { 'Version' => create_info(versions.join("\n"), status) } }
  end.reduce(:deep_merge)
end