Sha256: 41bd91686e169a9b43c080f0955e735cfd985956a6c361232bb7bb70d98f6af0
Contents?: true
Size: 1.98 KB
Versions: 18
Compression:
Stored size: 1.98 KB
Contents
# frozen_string_literal: true module AcidicJob module Extensions module Noticed extend ActiveSupport::Concern class_methods do def deliver_acidicly(recipients) new.deliver_acidicly(recipients) end end def deliver_acidicly(recipients) # THIS IS A HACK THAT COPIES AND PASTES KEY PARTS OF THE `Noticed::Base` CODE # IN ORDER TO ALLOW US TO TRANSACTIONALLY DELIVER NOTIFICATIONS # THIS IS THUS LIABLE TO BREAK WHENEVER THAT GEM IS UPDATED delivery_methods = self.class.delivery_methods.dup Array.wrap(recipients).uniq.each do |recipient| if (index = delivery_methods.find_index { |m| m[:name] == :database }) database_delivery_method = delivery_methods.delete_at(index) self.record = run_delivery_method(database_delivery_method, recipient: recipient, enqueue: false, record: nil) end delivery_methods.map do |delivery_method| job_class = delivery_method_for(delivery_method[:name], delivery_method[:options]) args = { notification_class: self.class.name, options: delivery_method[:options], params: params, recipient: recipient, record: record } serialized_job = job_class.send(:job_or_instantiate, args).serialize acidic_identifier = job_class.respond_to?(:acidic_identifier) ? job_class.acidic_identifier : :job_id key = IdempotencyKey.new(acidic_identifier).value_for(serialized_job) AcidicJob::Run.create!( staged: true, job_class: job_class.name, serialized_job: serialized_job, idempotency_key: key ) end end end alias deliver_transactionally deliver_acidicly end end end
Version data entries
18 entries across 18 versions & 1 rubygems