class ContainerWorkUnit < ProxyWorkUnit
- attr_accessor :related
+ attr_accessor :container
def initialize proxied, label
super
if @proxied.is_a?(ContainerRequest)
container_uuid = get(:container_uuid)
if container_uuid
- @related = Container.where(uuid: container_uuid).first rescue nil
+ @container = Container.where(uuid: container_uuid).first
end
end
end
def children
return self.my_children if self.my_children
- items = []
-
- if @proxied.is_a?(Container)
- crs = {}
- reqs = ContainerRequest.where(requesting_container_uuid: uuid).results
- reqs.each { |cr| crs[cr.container_uuid] = cr.name }
-
- containers = Container.where(uuid: crs.keys).results
- containers.each do |c|
- items << c.work_unit(crs[c.uuid] || 'this container')
- end
+ container_uuid = nil
+ container_uuid = if @proxied.is_a?(Container) then uuid else get(:container_uuid) end
- self.my_children = items
- else
- container_uuid = get(:container_uuid)
- if container_uuid
- reqs = ContainerRequest.where(requesting_container_uuid: container_uuid).results
- reqs.each do |cr|
- items << cr.work_unit(cr.name || 'this container')
- end
+ items = []
+ if container_uuid
+ reqs = ContainerRequest.where(requesting_container_uuid: container_uuid).results
+ reqs.each do |cr|
+ items << cr.work_unit(cr.name || 'this container')
end
end
"container"
end
+ def uri
+ uuid = get(:uuid)
+
+ return nil unless uuid
+
+ if @proxied.class.respond_to? :table_name
+ "/#{@proxied.class.table_name}/#{uuid}"
+ else
+ resource_class = ArvadosBase.resource_class_for_uuid(uuid)
+ "#{resource_class.table_name}/#{uuid}" if resource_class
+ end
+ end
+
def can_cancel?
- @proxied.is_a?(ContainerRequest) && state_label.in?(["Queued", "Locked", "Running"])
+ @proxied.is_a?(ContainerRequest) && state_label.in?(["Queued", "Locked", "Running"]) && priority > 0
end
def container_uuid
get(:container_uuid)
end
- # For the following properties, use value from the @related container if exists
- # This applies to a ContainerRequest in Committed or Final state with container_uuid
+ # For the following properties, use value from the @container if exists
+ # This applies to a ContainerRequest with container_uuid
def started_at
t = get_combined(:started_at)
get_combined(:output_path)
end
+ def log_object_uuids
+ [get_combined(:uuid), get(:uuid)].uniq
+ end
+
+ def live_log_lines(limit=2000)
+ event_types = ["stdout", "stderr", "arv-mount", "crunch-run"]
+ log_lines = Log.where(event_type: event_types, object_uuid: log_object_uuids).order("id DESC").limit(limit)
+ log_lines.results.reverse.
+ flat_map { |log| log.properties[:text].split("\n") rescue [] }
+ end
+
+ def render_log
+ collection = Collection.find(log_collection) rescue nil
+ if collection
+ return {log: collection, partial: 'collections/show_files', locals: {object: collection, no_checkboxes: true}}
+ end
+ end
+
+ def template_uuid
+ properties = get(:properties)
+ if properties
+ properties[:template_uuid]
+ end
+ end
+
# End combined propeties
protected
def get_combined key
- get(key, @related) || get(key, @proxied)
+ get(key, @container) || get(key, @proxied)
end
end