2798: Merged branch with code to read environment variables with branch working on...
[arvados.git] / services / api / app / models / job_task.rb
1 class JobTask < ArvadosModel
2   include AssignUuid
3   include KindAndEtag
4   include CommonApiTemplate
5   serialize :parameters, Hash
6   after_update :delete_created_job_tasks_if_failed
7   after_update :assign_created_job_tasks_qsequence_if_succeeded
8
9   api_accessible :user, extend: :common do |t|
10     t.add :job_uuid
11     t.add :created_by_job_task_uuid
12     t.add :sequence
13     t.add :qsequence
14     t.add :parameters
15     t.add :output
16     t.add :progress
17     t.add :success
18   end
19
20   protected
21
22   def delete_created_job_tasks_if_failed
23     if self.success == false and self.success != self.success_was
24       JobTask.delete_all ['created_by_job_task_uuid = ?', self.uuid]
25     end
26   end
27
28   def assign_created_job_tasks_qsequence_if_succeeded
29     if self.success == false and self.success != self.success_was
30       # xxx qsequence should be sequential as advertised; for now at
31       # least it's non-decreasing.
32       JobTask.update_all(['qsequence = ?', (Time.now.to_f*10000000).to_i],
33                          ['created_by_job_task_uuid = ?', self.uuid])
34     end
35   end
36 end