Merge branch '3187-start-finish-timestamps-tasks-pipelines' into 3187-pipeline-instan...
[arvados.git] / apps / workbench / app / models / job.rb
1 class Job < ArvadosBase
2   def self.goes_in_projects?
3     true
4   end
5
6   def content_summary
7     "#{script} job"
8   end
9
10   def attribute_editable? attr, *args
11     false
12   end
13
14   def self.creatable?
15     false
16   end
17
18   def default_name
19     if script
20       x = "\"#{script}\" job"
21     else
22       x = super
23     end
24     if finished_at
25       x += " finished #{finished_at.strftime('%b %-d')}"
26     elsif started_at
27       x += " started #{started_at.strftime('%b %-d')}"
28     elsif created_at
29       x += " submitted #{created_at.strftime('%b %-d')}"
30     end
31   end
32
33   def cancel
34     arvados_api_client.api "jobs/#{self.uuid}/", "cancel", {}
35   end
36
37   def state
38     Job::state(self)
39   end
40
41   def self.state job
42     if not job[:cancelled_at].nil?
43       "Canceled"
44     elsif not job[:finished_at].nil? or not job[:success].nil?
45       if job[:success]
46         "Completed"
47       else
48         "Failed"
49       end
50     elsif job[:running]
51       "Running"
52     else
53       "Queued"
54     end
55   end
56
57 end