Merge branch '4031-fix-graph-connections' closes #4031
[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 editable_attributes
11     %w(description)
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 self.queue_size
38     arvados_api_client.api("jobs/", "queue_size", {"_method"=> "GET"})[:queue_size] rescue 0
39   end
40
41   def self.queue
42     arvados_api_client.unpack_api_response arvados_api_client.api("jobs/", "queue", {"_method"=> "GET"})
43   end
44
45   def textile_attributes
46     [ 'description' ]
47   end
48 end