Module: Submission::DelayedJobBehaviour

Included in:
Submission
Defined in:
app/models/submission/delayed_job_behaviour.rb

Instance Method Summary collapse

Instance Method Details

#build_batchObject


12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/models/submission/delayed_job_behaviour.rb', line 12

def build_batch
  ActiveRecord::Base.transaction do
    finalize_build!
  end
rescue ActiveRecord::StatementInvalid => e
  # If an SQL problems occurs, it's more likely that's it's
  # a one shot one, e.g. timeout , deadlock etc ...
  # So we don't want the submission to fail but the delayed job to
  # retry later. Therefore the DelayedJob should fail
  raise e
rescue ActiveRecord::RecordInvalid, Submission::ProjectValidation::Error => e
  Rails.logger.error(e.message)
  Rails.logger.error(e.backtrace)
  fail_set_message_and_save(e.message)
rescue => e
  Rails.logger.error(e.message)
  Rails.logger.error(e.backtrace)
  fail_set_message_and_save("#{e.message}\n#{e.backtrace.join("\n")}")
end

#complete_buildingObject


6
7
8
9
10
# File 'app/models/submission/delayed_job_behaviour.rb', line 6

def complete_building
  super
  # Lower priorities get processed faster. This ensures high priority submissions get processed first.
  Delayed::Job.enqueue SubmissionBuilderJob.new(id), priority: default_priority - priority
end

#default_priorityObject


2
3
4
# File 'app/models/submission/delayed_job_behaviour.rb', line 2

def default_priority
  configatron.delayed_job.fetch(:submission_process_priority, 0)
end

#finalize_build!Object


32
33
34
35
# File 'app/models/submission/delayed_job_behaviour.rb', line 32

def finalize_build!
  process!
  ready!
end