X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/43c411ec1441ee1710dc33389d7451f7414a170f..8ca0b1449607ded51e908481cc4660c20f43a777:/apps/workbench/app/models/job.rb?ds=sidebyside diff --git a/apps/workbench/app/models/job.rb b/apps/workbench/app/models/job.rb index e716df75f9..7c55d9e857 100644 --- a/apps/workbench/app/models/job.rb +++ b/apps/workbench/app/models/job.rb @@ -1,2 +1,63 @@ +# Copyright (C) The Arvados Authors. All rights reserved. +# +# SPDX-License-Identifier: AGPL-3.0 + class Job < ArvadosBase + def self.goes_in_projects? + true + end + + def content_summary + "#{script} job" + end + + def editable_attributes + %w(description) + end + + def default_name + if script + x = "\"#{script}\" job" + else + x = super + end + if finished_at + x += " finished #{finished_at.strftime('%b %-d')}" + elsif started_at + x += " started #{started_at.strftime('%b %-d')}" + elsif created_at + x += " submitted #{created_at.strftime('%b %-d')}" + end + end + + def cancel + arvados_api_client.api "jobs/#{self.uuid}/", "cancel", {"cascade" => true} + end + + def self.queue_size + arvados_api_client.api("jobs/", "queue_size", {"_method"=> "GET"})[:queue_size] rescue 0 + end + + def self.queue + arvados_api_client.unpack_api_response arvados_api_client.api("jobs/", "queue", {"_method"=> "GET"}) + end + + def textile_attributes + [ 'description' ] + end + + def stderr_log_query(limit=nil) + query = Log.where(object_uuid: self.uuid).order("created_at DESC").with_count('none') + query = query.limit(limit) if limit + query + end + + def stderr_log_lines(limit=2000) + stderr_log_query(limit).results.reverse. + flat_map { |log| log.properties[:text].split("\n") rescue [] } + end + + def work_unit(label=nil) + JobWorkUnit.new(self, label, self.uuid) + end end