Class: Coil::TransactionalMessagesJob
- Inherits:
-
ApplicationJob
- Object
- ApplicationJob
- Coil::TransactionalMessagesJob
- Defined in:
- app/jobs/coil/transactional_messages_job.rb
Constant Summary collapse
- RetryableError =
Class.new(StandardError)
- DuplicateJobError =
Class.new(StandardError)
- MAX_DURATION =
Sidekiq is not designed for long-running jobs, so we place an upper bound on job duration. When a job exceeds this bound, we’ll enqueue a subsequent job to pick up where we left off.
5.minutes
Instance Method Summary collapse
Instance Method Details
#perform(key, processor_name = self.class.to_s) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'app/jobs/coil/transactional_messages_job.rb', line 15 def perform(key, processor_name = self.class.to_s) deadline = Time.current + MAX_DURATION next_in_line = (key:, processor_name:, deadline:) return if next_in_line.nil? # If we reach this point, it means we exceeded the deadline and there # are messages we still haven't processed. Rails.logger.info(<<~INFO.squish) #{self.class} exceeded deadline. Enqueuing subsequent job with key=#{key} processor_name=#{processor_name} INFO next_in_line.enqueue_job(processor_name) rescue DuplicateJobError # A duplicate job is in the midst of its message-processing loop. We'll # call this job done and allow the other one to continue. end |