8876: remove some job specific bits and make them generic
[arvados.git] / apps / workbench / app / models / proxy_work_unit.rb
1 class ProxyWorkUnit < WorkUnit
2   require 'time'
3
4   attr_accessor :lbl
5   attr_accessor :proxied
6   attr_accessor :unreadable_children
7
8   def initialize proxied, label
9     self.lbl = label
10     self.proxied = proxied
11   end
12
13   def label
14     self.lbl
15   end
16
17   def uuid
18     get(:uuid)
19   end
20
21   def modified_by_user_uuid
22     get(:modified_by_user_uuid)
23   end
24
25   def created_at
26     t = get(:created_at)
27     t = Time.parse(t) if (t.andand.class == String)
28     t
29   end
30
31   def started_at
32     t = get(:started_at)
33     t = Time.parse(t) if (t.andand.class == String)
34     t
35   end
36
37   def finished_at
38     t = get(:finished_at)
39     t = Time.parse(t) if (t.andand.class == String)
40     t
41   end
42
43   def state_label
44     state = get(:state)
45     if ["Running", "RunningOnServer", "RunningOnClient"].include? state
46       "Running"
47     else
48       state
49     end
50   end
51
52   def state_bootstrap_class
53     state = get(:state)
54     case state
55     when 'Complete'
56       'success'
57     when 'Failed', 'Cancelled'
58       'danger'
59     when 'Running', 'RunningOnServer', 'RunningOnClient'
60       'info'
61     else
62       'default'
63     end
64   end
65
66   def success?
67     state = get(:state)
68     if state == 'Complete'
69       true
70     elsif state == 'Failed'
71       false
72     else
73       nil
74     end
75   end
76
77   def parameters
78     get(:script_parameters)
79   end
80
81   def repository
82     get(:repository)
83   end
84
85   def script
86     get(:script)
87   end
88
89   def script_version
90     get(:script_version)
91   end
92
93   def supplied_script_version
94     get(:supplied_script_version)
95   end
96
97   def runtime_constraints
98     get(:runtime_constraints)
99   end
100
101   def children
102     []
103   end
104
105   def title
106     "work unit"
107   end
108
109   def has_unreadable_children
110     self.unreadable_children
111   end
112
113   def readable?
114     resource_class = ArvadosBase::resource_class_for_uuid(uuid)
115     resource_class.where(uuid: [uuid]).first rescue nil
116   end
117
118   protected
119
120   def get key
121     if self.proxied.respond_to? key
122       self.proxied.send(key)
123     elsif self.proxied.is_a?(Hash)
124       self.proxied[key]
125     end
126   end
127 end