X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/1cf15bae4e5236084c338fb557c749533adce679..0cf2f356035164cd92e4a5722f0dd25c7502164e:/services/api/app/models/job.rb diff --git a/services/api/app/models/job.rb b/services/api/app/models/job.rb index 654778aa44..32f28e3582 100644 --- a/services/api/app/models/job.rb +++ b/services/api/app/models/job.rb @@ -6,11 +6,11 @@ class Job < ArvadosModel serialize :script_parameters, Hash serialize :runtime_constraints, Hash serialize :tasks_summary, Hash - before_validation :find_docker_image_locator before_create :ensure_unique_submit_id - before_create :ensure_script_version_is_commit - before_update :ensure_script_version_is_commit after_commit :trigger_crunch_dispatch_if_cancelled, :on => :update + before_validation :set_priority + validate :ensure_script_version_is_commit + validate :find_docker_image_locator has_many :commit_ancestors, :foreign_key => :descendant, :primary_key => :script_version @@ -29,7 +29,6 @@ class Job < ArvadosModel t.add :started_at t.add :finished_at t.add :output - t.add :output_is_persistent t.add :success t.add :running t.add :is_locked_by_uuid @@ -41,6 +40,7 @@ class Job < ArvadosModel t.add :repository t.add :supplied_script_version t.add :docker_image_locator + t.add :description end def assert_finished @@ -74,6 +74,13 @@ class Job < ArvadosModel super + %w(output log) end + def set_priority + if self.priority.nil? + self.priority = 0 + end + true + end + def ensure_script_version_is_commit if self.is_locked_by_uuid and self.started_at # Apparently client has already decided to go for it. This is @@ -87,7 +94,8 @@ class Job < ArvadosModel self.supplied_script_version = self.script_version if self.supplied_script_version.nil? or self.supplied_script_version.empty? self.script_version = sha1 else - raise ArgumentError.new("Specified script_version does not resolve to a commit") + self.errors.add :script_version, "#{self.script_version} does not resolve to a commit" + return false end end end @@ -104,16 +112,22 @@ class Job < ArvadosModel def find_docker_image_locator # Find the Collection that holds the Docker image specified in the # runtime constraints, and store its locator in docker_image_locator. - if runtime_constraints.nil? then + unless runtime_constraints.is_a? Hash + # We're still in validation stage, so we can't assume + # runtime_constraints isn't something horrible like an array or + # a string. Treat those cases as "no docker image supplied"; + # other validations will fail anyway. self.docker_image_locator = nil - return false + return true end image_search = runtime_constraints['docker_image'] image_tag = runtime_constraints['docker_image_tag'] if image_search.nil? self.docker_image_locator = nil + true elsif coll = Collection.for_latest_docker_image(image_search, image_tag) - self.docker_image_locator = coll.uuid + self.docker_image_locator = coll.portable_data_hash + true else errors.add(:docker_image_locator, "not found for #{image_search}") false @@ -185,7 +199,7 @@ class Job < ArvadosModel if self.cancelled_at and not self.cancelled_at_was self.cancelled_at = Time.now self.cancelled_by_user_uuid = current_user.uuid - self.cancelled_by_client_uuid = current_api_client.uuid + self.cancelled_by_client_uuid = current_api_client.andand.uuid @need_crunch_dispatch_trigger = true else self.cancelled_at = self.cancelled_at_was