X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/2f1baf225599d7ae5dec4611696774e6a7100d58..04bd6b08b9ac13d29ac05c9281850d430d71066d:/apps/workbench/app/models/job.rb diff --git a/apps/workbench/app/models/job.rb b/apps/workbench/app/models/job.rb index 92f3910293..128440d526 100644 --- a/apps/workbench/app/models/job.rb +++ b/apps/workbench/app/models/job.rb @@ -1,13 +1,59 @@ class Job < ArvadosBase - def self.goes_in_folders? + def self.goes_in_projects? true end - def attribute_editable? attr, *args - false + def content_summary + "#{script} job" end - def self.creatable? - false + 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