Class: Coil::TransactionalMessagesPeriodicJob

Inherits:
ApplicationJob show all
Defined in:
app/jobs/coil/transactional_messages_periodic_job.rb

Instance Method Summary collapse

Instance Method Details

#performObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/jobs/coil/transactional_messages_periodic_job.rb', line 8

def perform
  t = Time.current - TransactionalMessagesJob::MAX_DURATION

  # Identify distinct message types, their associated job types, and
  # the distinct keys for which we have unprocessed messages (excluding
  # very recent messages, since a TransactionalMessagesJob may still be
  # processing those). Then, enqueue the necessary jobs for those keys.
  message_parent_class.select(:type).distinct.each do |x|
    message_class = x.class
    job_class = x.job_class

    message_class
      .unprocessed(processor_name: job_class.name)
      .where(created_at: nil...t)
      .distinct
      .pluck(:key)
      .each { |k| job_class.perform_async(k) }
  end
end