6087: Get database time only once per manifest-signing/verifying event, rather than...
[arvados.git] / services / api / app / models / job_task.rb
1 class JobTask < ArvadosModel
2   include HasUuid
3   include KindAndEtag
4   include CommonApiTemplate
5   serialize :parameters, Hash
6   before_create :set_default_qsequence
7   after_update :delete_created_job_tasks_if_failed
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     t.add :started_at
19     t.add :finished_at
20   end
21
22   protected
23
24   def delete_created_job_tasks_if_failed
25     if self.success == false and self.success != self.success_was
26       JobTask.delete_all ['created_by_job_task_uuid = ?', self.uuid]
27     end
28   end
29
30   def set_default_qsequence
31     self.qsequence ||= self.class.connection.
32       select_value("SELECT nextval('job_tasks_qsequence_seq')")
33   end
34 end