13561: Sync selected fields changes with older versions, with tests.
[arvados.git] / services / api / app / models / job_task.rb
1 # Copyright (C) The Arvados Authors. All rights reserved.
2 #
3 # SPDX-License-Identifier: AGPL-3.0
4
5 class JobTask < ArvadosModel
6   include HasUuid
7   include KindAndEtag
8   include CommonApiTemplate
9   serialize :parameters, Hash
10   before_create :set_default_qsequence
11   after_update :delete_created_job_tasks_if_failed
12
13   api_accessible :user, extend: :common do |t|
14     t.add :job_uuid
15     t.add :created_by_job_task_uuid
16     t.add :sequence
17     t.add :qsequence
18     t.add :parameters
19     t.add :output
20     t.add :progress
21     t.add :success
22     t.add :started_at
23     t.add :finished_at
24   end
25
26   protected
27
28   def delete_created_job_tasks_if_failed
29     if self.success == false and self.success != self.success_was
30       JobTask.delete_all ['created_by_job_task_uuid = ?', self.uuid]
31     end
32   end
33
34   def set_default_qsequence
35     self.qsequence ||= self.class.connection.
36       select_value("SELECT nextval('job_tasks_qsequence_seq')")
37   end
38 end