Merge branch 'master' of git.clinicalfuture.com:orvos-server
[arvados.git] / app / models / job.rb
1 class Job < OrvosModel
2   include AssignUuid
3   include KindAndEtag
4   include CommonApiTemplate
5   serialize :command_parameters, Hash
6   before_create :ensure_unique_submit_id
7
8   class SubmitIdReused < StandardError
9   end
10
11   api_accessible :superuser, :extend => :common do |t|
12     t.add :submit_id
13     t.add :priority
14     t.add :command
15     t.add :command_parameters
16     t.add :command_version
17     t.add :cancelled_at
18     t.add :cancelled_by_client
19     t.add :cancelled_by_user
20     t.add :started_at
21     t.add :finished_at
22     t.add :success
23     t.add :running
24   end
25
26   protected
27
28   def ensure_unique_submit_id
29     if !submit_id.nil?
30       if Job.where('submit_id=?',self.submit_id).first
31         raise SubmitIdReused.new
32       end
33     end
34     true
35   end
36 end