X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/aface0b74e6b3cfaaa8d773218a5ada423a7654b..0821f5481edd016a3744bb50d97a9e5b99cd1a0f:/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..11ec0ee196 100644 --- a/apps/workbench/app/models/proxy_work_unit.rb +++ b/apps/workbench/app/models/proxy_work_unit.rb @@ -7,12 +7,12 @@ class ProxyWorkUnit < WorkUnit attr_accessor :unreadable_children def initialize proxied, label - self.lbl = label - self.proxied = proxied + @lbl = label + @proxied = proxied end def label - self.lbl + @lbl end def uuid @@ -23,21 +23,31 @@ class ProxyWorkUnit < WorkUnit 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 +55,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 +77,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 +135,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 +157,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,7 +170,7 @@ class ProxyWorkUnit < WorkUnit end def has_unreadable_children - self.unreadable_children + @unreadable_children end def readable? @@ -237,8 +209,7 @@ class ProxyWorkUnit < WorkUnit def cputime if state_label != "Queued" if started_at - (runtime_constraints.andand[:min_nodes] || 1) * - ((finished_at || Time.now()) - started_at) + (runtime_constraints.andand[:min_nodes] || 1) * ((finished_at || Time.now()) - started_at) end end end @@ -249,14 +220,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 +236,118 @@ class ProxyWorkUnit < WorkUnit state_label == 'Failed' end - def can_be_canceled? - state_label.in? ["Queued", "Running"] and can_cancel? - end + def show_runtime + runningtime = ApplicationController.helpers.determine_wallclock_runtime(if children.any? then children else [self] 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" + walltime = 0 + if started_at + walltime = if finished_at then (finished_at - started_at) else (Time.now - started_at) end end - ran_for - end - def started_and_active_for_str - active_for = nil + 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 " + else + resp << "has been active for " + end + + if walltime > runningtime + resp << ApplicationController.helpers.render_time(walltime, false) + else + resp << ApplicationController.helpers.render_time(runningtime, false) + end + + 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? + resp << " Check the Log tab for more detail about why it failed." + end + resp << "

" + + resp << "

" + if state_label + resp << "It " + if state_label == 'Running' + resp << "has run" else - active_for_2 << "has been active for " + resp << "ran" + end + resp << " for " + + cpu_time = 0 + if children.any? + cpu_time = children.map { |c| + if c.started_at + (c.runtime_constraints.andand[:min_nodes] || 1) * ((c.finished_at || Time.now()) - c.started_at) + else + 0 + end + }.reduce(:+) || 0 + else + if started_at + cpu_time = (runtime_constraints.andand[:min_nodes] || 1) * ((finished_at || Time.now()) - started_at) + end + end + + resp << ApplicationController.helpers.render_time(runningtime, false) + if (walltime - runningtime) > 0 + resp << "(" + resp << ApplicationController.helpers.render_time(walltime - runningtime, 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/runningtime).round(1).to_s + resp << "⨯ scaling)." end - [active_for_1, active_for_2] 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). + 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] end end end