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



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

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



64
65
66
# File 'app/models/naf/running_job.rb', line 64

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

.in_run_group(run_group_name) ⇒ Object



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

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

.started_on(machine) ⇒ Object


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



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

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

.started_on_invocation(invocation_id) ⇒ Object



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

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 *** +++++++++++++++++++++++++



92
93
94
95
96
97
98
99
100
101
102
103
# File 'app/models/naf/running_job.rb', line 92

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



115
116
117
118
# File 'app/models/naf/running_job.rb', line 115

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

#remove_tags(tags_to_remove) ⇒ Object



105
106
107
108
109
110
111
112
113
# File 'app/models/naf/running_job.rb', line 105

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