Module: Submission::DelayedJobBehaviour

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

Instance Method Summary collapse

Instance Method Details

#build_batchObject

rubocop:todo Metrics/MethodLength



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

def build_batch # rubocop:todo Metrics/AbcSize
  ActiveRecord::Base.transaction { finalize_build! }
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

#default_priorityObject



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

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

#finalize_build!Object

rubocop:enable Metrics/MethodLength



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

def finalize_build!
  process!
  ready!
end

#queue_submission_builderObject



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

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