8876: progress bar and strage component display
[arvados.git] / apps / workbench / app / models / job_work_unit.rb
1 class JobWorkUnit < ProxyWorkUnit
2   def children
3     # Job tasks
4     uuid = get(:uuid)
5     tasks = JobTask.filter([['job_uuid', '=', uuid]]).results
6     items = []
7     tasks.each do |t|
8       items << t.work_unit("task #{items.size}")
9     end
10
11     # Jobs submitted by this job  --  TBD
12
13     items
14   end
15
16   def progress
17     state = get(:state)
18     if state == 'Complete'
19       return 1.0
20     end
21
22     tasks_summary = get(:tasks_summary)
23     failed = tasks_summary[:failed] || 0 rescue 0
24     done = tasks_summary[:done] || 0 rescue 0
25     running = tasks_summary[:running] || 0 rescue 0
26     todo = tasks_summary[:todo] || 0 rescue 0
27     if done + running + failed + todo > 0
28       total_tasks = done + running + failed + todo
29       (done+failed).to_f / total_tasks
30     else
31       0.0
32     end
33   end
34
35   def docker_image
36     get(:docker_image_locator)
37   end
38
39   def nondeterministic
40     get(:nondeterministic)
41   end
42
43   def priority
44     get(:priority)
45   end
46
47   def log_collection
48     get(:log)
49   end
50
51   def output
52     get(:output)
53   end
54
55   def can_cancel?
56     true
57   end
58
59   def uri
60     uuid = get(:uuid)
61     "/jobs/#{uuid}"
62   end
63
64   def child_summary
65     get(:tasks_summary)
66   end
67
68   def title
69     "job"
70   end
71 end