X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/97bb0917adfeb4db73c4c27cac8e337828c34015..495a7df016f63ae348000b1c046f8e1c5f1c5903:/services/api/app/models/job.rb diff --git a/services/api/app/models/job.rb b/services/api/app/models/job.rb index a86cc62bf2..2ae7139281 100644 --- a/services/api/app/models/job.rb +++ b/services/api/app/models/job.rb @@ -2,6 +2,7 @@ class Job < ArvadosModel include HasUuid include KindAndEtag include CommonApiTemplate + extend CurrentApiClient serialize :components, Hash attr_protected :arvados_sdk_version, :docker_image_locator serialize :script_parameters, Hash @@ -66,6 +67,10 @@ class Job < ArvadosModel (Complete = 'Complete'), ] + after_initialize do + @need_crunch_dispatch_trigger = false + end + def assert_finished update_attributes(finished_at: finished_at || db_current_time, success: success.nil? ? false : success, @@ -114,6 +119,10 @@ class Job < ArvadosModel super - ["script_parameters_digest"] end + def self.full_text_searchable_columns + super - ["script_parameters_digest"] + end + def self.load_job_specific_filters attrs, orig_filters, read_users # Convert Job-specific @filters entries into general SQL filters. script_info = {"repository" => nil, "script" => nil} @@ -281,18 +290,6 @@ class Job < ArvadosModel Digest::MD5.hexdigest(Oj.dump(deep_sort_hash(h))) end - def self.deep_sort_hash x - if x.is_a? Hash - x.sort.collect do |k, v| - [k, deep_sort_hash(v)] - end.to_h - elsif x.is_a? Array - x.collect { |v| deep_sort_hash(v) } - else - x - end - end - def foreign_key_attributes super + %w(output log) end @@ -347,7 +344,7 @@ class Job < ArvadosModel assign_uuid Commit.tag_in_internal_repository repository, script_version, uuid rescue - uuid = uuid_was + self.uuid = uuid_was raise end end @@ -426,7 +423,7 @@ class Job < ArvadosModel output_changed? or log_changed? or tasks_summary_changed? or - state_changed? or + (state_changed? && state != Cancelled) or components_changed? logger.warn "User #{current_user.uuid if current_user} tried to change protected job attributes on locked #{self.class.to_s} #{uuid_was}" return false @@ -576,24 +573,6 @@ class Job < ArvadosModel end def ensure_no_collection_uuids_in_script_params - # recursive_hash_search searches recursively through hashes and - # arrays in 'thing' for string fields matching regular expression - # 'pattern'. Returns true if pattern is found, false otherwise. - def recursive_hash_search thing, pattern - if thing.is_a? Hash - thing.each do |k, v| - return true if recursive_hash_search v, pattern - end - elsif thing.is_a? Array - thing.each do |k| - return true if recursive_hash_search k, pattern - end - elsif thing.is_a? String - return true if thing.match pattern - end - false - end - # Fail validation if any script_parameters field includes a string containing a # collection uuid pattern. if self.script_parameters_changed? @@ -604,4 +583,22 @@ class Job < ArvadosModel end true end + + # recursive_hash_search searches recursively through hashes and + # arrays in 'thing' for string fields matching regular expression + # 'pattern'. Returns true if pattern is found, false otherwise. + def recursive_hash_search thing, pattern + if thing.is_a? Hash + thing.each do |k, v| + return true if recursive_hash_search v, pattern + end + elsif thing.is_a? Array + thing.each do |k| + return true if recursive_hash_search k, pattern + end + elsif thing.is_a? String + return true if thing.match pattern + end + false + end end