Class: Naf::RunningJob

Inherits:
NafBase show all
Defined in:
app/models/naf/running_job.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from NafBase

full_table_name_prefix

Class Method Details

.affinity_weights(machine) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'app/models/naf/running_job.rb', line 65

def self.affinity_weights(machine)
  affinity_ids = ::Naf::Affinity.all.map(&:id)

  job_weights = {}
  affinity_ids.each do |affinity_id|
    job_weights[affinity_id] = 0
  end

  ::Naf::RunningJob.where(started_on_machine_id: machine.id).all.each do |running_job|
    affinity_ids.each do |affinity_id|
      job_weights[affinity_id] += running_job.
        historical_job.historical_job_affinity_tabs.
        where(affinity_id: affinity_id).
        first.try(:affinity_parameter).to_f
    end
  end

  job_weights
end

.assigned_jobs(machine) ⇒ Object



61
62
63
# File 'app/models/naf/running_job.rb', line 61

def self.assigned_jobs(machine)
  started_on(machine)
end

.in_run_group(run_group_name) ⇒ Object



57
58
59
# File 'app/models/naf/running_job.rb', line 57

def self.in_run_group(run_group_name)
  where(application_run_group_name: run_group_name)
end

.started_on(machine) ⇒ Object


*** Class Methods *** +++++++++++++++++++++++++



48
49
50
# File 'app/models/naf/running_job.rb', line 48

def self.started_on(machine)
  where(started_on_machine_id: machine.id)
end

.started_on_invocation(invocation_id) ⇒ Object



52
53
54
55
# File 'app/models/naf/running_job.rb', line 52

def self.started_on_invocation(invocation_id)
  joins(:historical_job).
  where("#{::Naf.schema_name}.historical_jobs.machine_runner_invocation_id = #{invocation_id}")
end

Instance Method Details

#add_tags(tags_to_add) ⇒ Object


*** Instance Methods *** +++++++++++++++++++++++++



89
90
91
92
93
94
95
96
97
98
99
100
# File 'app/models/naf/running_job.rb', line 89

def add_tags(tags_to_add)
  tags_array = nil
  if self.tags.present?
    tags_array = self.tags.gsub(/[{}]/,'').split(',')
    new_tags = '{' + (tags_array | tags_to_add).join(',') + '}'
  else
    new_tags = '{' + tags_to_add.join(',') + '}'
  end

  self.tags = new_tags
  self.save!
end

#remove_all_tagsObject



112
113
114
115
# File 'app/models/naf/running_job.rb', line 112

def remove_all_tags
  self.tags = '{}'
  self.save!
end

#remove_tags(tags_to_remove) ⇒ Object



102
103
104
105
106
107
108
109
110
# File 'app/models/naf/running_job.rb', line 102

def remove_tags(tags_to_remove)
  if self.tags.present?
    tags_array = self.tags.gsub(/[{}]/,'').split(',')
    new_tags = '{' + (tags_array - tags_to_remove).join(',') + '}'

    self.tags = new_tags
    self.save!
  end
end