app/models/naf/running_job.rb in naf-1.1.4 vs app/models/naf/running_job.rb in naf-2.0.0
- old
+ new
@@ -10,11 +10,12 @@
:started_on_machine_id,
:pid,
:request_to_terminate,
:marked_dead_by_machine_id,
:log_level,
- :started_at
+ :started_at,
+ :tags
#---------------------
# *** Associations ***
#+++++++++++++++++++++
@@ -46,10 +47,15 @@
def self.started_on(machine)
where(started_on_machine_id: machine.id)
end
+ def self.started_on_invocation(invocation_id)
+ joins(:historical_job).
+ where("#{::Naf.schema_name}.historical_jobs.machine_runner_invocation_id = #{invocation_id}")
+ end
+
def self.in_run_group(run_group_name)
where(application_run_group_name: run_group_name)
end
def self.assigned_jobs(machine)
@@ -73,8 +79,41 @@
end
end
job_weights
end
+
+ #-------------------------
+ # *** Instance Methods ***
+ #+++++++++++++++++++++++++
+
+ 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
+
+ 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
+
+ def remove_all_tags
+ self.tags = '{}'
+ self.save!
+ end
+
end
end