X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/aface0b74e6b3cfaaa8d773218a5ada423a7654b..0adb096afc227db376823f84956de6d7ea30dc10:/apps/workbench/app/models/proxy_work_unit.rb diff --git a/apps/workbench/app/models/proxy_work_unit.rb b/apps/workbench/app/models/proxy_work_unit.rb index 231145a4b2..adf0bd7d67 100644 --- a/apps/workbench/app/models/proxy_work_unit.rb +++ b/apps/workbench/app/models/proxy_work_unit.rb @@ -1,3 +1,7 @@ +# Copyright (C) The Arvados Authors. All rights reserved. +# +# SPDX-License-Identifier: AGPL-3.0 + class ProxyWorkUnit < WorkUnit require 'time' @@ -6,38 +10,53 @@ class ProxyWorkUnit < WorkUnit attr_accessor :my_children attr_accessor :unreadable_children - def initialize proxied, label - self.lbl = label - self.proxied = proxied + def initialize proxied, label, parent + @lbl = label + @proxied = proxied + @parent = parent end def label - self.lbl + @lbl end def uuid get(:uuid) end + def parent + @parent + end + def modified_by_user_uuid get(:modified_by_user_uuid) end + def owner_uuid + get(:owner_uuid) + end + def created_at t = get(:created_at) - t = Time.parse(t) if (t.andand.class == String) + t = Time.parse(t) if (t.is_a? String) t end def started_at t = get(:started_at) - t = Time.parse(t) if (t.andand.class == String) + t = Time.parse(t) if (t.is_a? String) + t + end + + def modified_at + t = get(:modified_at) + t = Time.parse(t) if (t.is_a? String) t end def finished_at t = get(:finished_at) - t = Time.parse(t) if (t.andand.class == String) + t = Time.parse(t) if (t.is_a? String) t end @@ -45,13 +64,15 @@ class ProxyWorkUnit < WorkUnit state = get(:state) if ["Running", "RunningOnServer", "RunningOnClient"].include? state "Running" + elsif state == 'New' + "Not started" else state end end def state_bootstrap_class - state = get(:state) + state = state_label case state when 'Complete' 'success' @@ -65,7 +86,7 @@ class ProxyWorkUnit < WorkUnit end def success? - state = get(:state) + state = state_label if state == 'Complete' true elsif state == 'Failed' or state == 'Cancelled' @@ -123,7 +144,7 @@ class ProxyWorkUnit < WorkUnit end def progress - state = get(:state) + state = state_label if state == 'Complete' return 1.0 elsif state == 'Failed' or state == 'Cancelled' @@ -145,51 +166,11 @@ class ProxyWorkUnit < WorkUnit end end - def parameters - get(:script_parameters) - end - - def repository - get(:repository) - end - - def script - get(:script) - end - - def script_version - get(:script_version) - end - - def supplied_script_version - get(:supplied_script_version) - end - - def docker_image - get(:docker_image_locator) - end - - def nondeterministic - get(:nondeterministic) - end - - def runtime_constraints - get(:runtime_constraints) - end - - def priority - get(:priority) - end - - def log_collection - get(:log) - end - - def output - get(:output) + def children + [] end - def children + def outputs [] end @@ -198,32 +179,7 @@ class ProxyWorkUnit < WorkUnit end def has_unreadable_children - self.unreadable_children - end - - def readable? - resource_class = ArvadosBase::resource_class_for_uuid(uuid) - resource_class.where(uuid: [uuid]).first rescue nil - end - - def link_to_log - if state_label.in? ["Complete", "Failed", "Cancelled"] - lc = log_collection - if lc - logCollection = Collection.find? lc - if logCollection - ApplicationController.helpers.link_to("Log", "#{uri}#Log") - else - "Log unavailable" - end - end - elsif state_label == "Running" - if readable? - ApplicationController.helpers.link_to("Log", "#{uri}#Log") - else - "Log unavailable" - end - end + @unreadable_children end def walltime @@ -235,10 +191,15 @@ class ProxyWorkUnit < WorkUnit end def cputime - if state_label != "Queued" + if children.any? + children.map { |c| + c.cputime + }.reduce(:+) || 0 + else if started_at - (runtime_constraints.andand[:min_nodes] || 1) * - ((finished_at || Time.now()) - started_at) + (runtime_constraints.andand[:min_nodes] || 1).to_i * ((finished_at || Time.now()) - started_at) + else + 0 end end end @@ -249,14 +210,6 @@ class ProxyWorkUnit < WorkUnit end end - def show_child_summary - if state_label == "Running" - if child_summary - child_summary_str - end - end - end - def is_running? state_label == 'Running' end @@ -273,48 +226,114 @@ class ProxyWorkUnit < WorkUnit state_label == 'Failed' end - def can_be_canceled? - state_label.in? ["Queued", "Running"] and can_cancel? + def runtime_contributors + contributors = [] + if children.any? + children.each{|c| contributors << c.runtime_contributors} + else + contributors << self + end + contributors.flatten end - def ran_for_str - ran_for = nil - if state_label - ran_for = "It " - if state_label == 'Running' - ran_for << "has run" - else - ran_for << "ran" - end - ran_for << " for" - end - ran_for + def runningtime + ApplicationController.helpers.determine_wallclock_runtime runtime_contributors end - def started_and_active_for_str - active_for = nil + def show_runtime + walltime = 0 + running_time = runningtime + if started_at + walltime = if finished_at then (finished_at - started_at) else (Time.now - started_at) end + end + resp = '

' if started_at - active_for_1 = "This #{title} started at " - active_for_2 = "It " + resp << "This #{title} started at " + resp << ApplicationController.helpers.render_localized_date(started_at) + resp << ". It " if state_label == 'Complete' - active_for_2 << "completed in " + resp << "completed in " elsif state_label == 'Failed' - active_for_2 << "failed after " + resp << "failed after " + elsif state_label == 'Cancelled' + resp << "was cancelled after " else - active_for_2 << "has been active for " + resp << "has been active for " + end + + resp << ApplicationController.helpers.render_time(walltime, false) + + if finished_at + resp << " at " + resp << ApplicationController.helpers.render_localized_date(finished_at) + end + resp << "." + else + if state_label + resp << "This #{title} is " + resp << if state_label == 'Running' then 'active' else state_label.downcase end + resp << "." + end + end + + if is_failed? + if runtime_status.andand[:error] + resp << " Check the error information below." + else + resp << " Check the Log tab for more detail about why it failed." end - [active_for_1, active_for_2] end + resp << "

" + + resp << "

" + if state_label + resp << "It has runtime of " + + cpu_time = cputime + + resp << ApplicationController.helpers.render_time(running_time, false) + if (walltime - running_time) > 0 + resp << "(" + resp << ApplicationController.helpers.render_time(walltime - running_time, false) + resp << "queued)" + end + if cpu_time == 0 + resp << "." + else + resp << " and used " + resp << ApplicationController.helpers.render_time(cpu_time, false) + resp << " of node allocation time (" + resp << (cpu_time/running_time).round(1).to_s + resp << "⨯ scaling)." + end + end + resp << "

" + + resp + end + + def log_object_uuids + [uuid] + end + + def live_log_lines(limit) + Log.where(object_uuid: log_object_uuids). + order("created_at DESC"). + limit(limit). + with_count('none'). + select { |log| log.properties[:text].is_a? String }. + reverse. + flat_map { |log| log.properties[:text].split("\n") } end protected - def get key - if self.proxied.respond_to? key - self.proxied.send(key) - elsif self.proxied.is_a?(Hash) - self.proxied[key] + def get key, obj=@proxied + if obj.respond_to? key + obj.send(key) + elsif obj.is_a?(Hash) + obj[key] || obj[key.to_s] end end end