Sha256: 3baccf6da2410af20f0d1d5f726f9cf89831dd6ff2de4fafde7826f2345e2ffd

Contents?: true

Size: 935 Bytes

Versions: 17

Compression:

Stored size: 935 Bytes

Contents

# frozen_string_literal: true

module Heya
  module Campaigns
    class StepActionJob < ActiveJob::Base
      queue_as { Heya.config.campaigns.queue }

      rescue_from StandardError, with: :handle_exception_with_campaign_class

      def perform(_campaign, user, step)
        step.action.new(user: user, step: step).deliver_now
      end

      private

      # From ActionMailer: "deserialize" the mailer class name by hand in case
      # another argument (like a Global ID reference) raised
      # DeserializationError.
      def campaign_class
        if (campaign = (arguments_serialized? && Array(@serialized_arguments).first) || Array(arguments).first)
          campaign.constantize
        end
      end

      def handle_exception_with_campaign_class(exception)
        if (klass = campaign_class)
          klass.handle_exception(exception)
        else
          raise exception
        end
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
heya-0.12.0 lib/heya/campaigns/step_action_job.rb
heya-0.11.0 lib/heya/campaigns/step_action_job.rb
heya-0.10.0 lib/heya/campaigns/step_action_job.rb
heya-0.9.0 lib/heya/campaigns/step_action_job.rb
heya-0.8.0 lib/heya/campaigns/step_action_job.rb
heya-0.7.0 lib/heya/campaigns/step_action_job.rb
heya-0.6.1 lib/heya/campaigns/step_action_job.rb
heya-0.6.0 lib/heya/campaigns/step_action_job.rb
heya-0.5.3 lib/heya/campaigns/step_action_job.rb
heya-0.5.2 lib/heya/campaigns/step_action_job.rb
heya-0.5.1 lib/heya/campaigns/step_action_job.rb
heya-0.5.0 lib/heya/campaigns/step_action_job.rb
heya-0.4.0 lib/heya/campaigns/step_action_job.rb
heya-0.3.0 lib/heya/campaigns/step_action_job.rb
heya-0.2.1 lib/heya/campaigns/step_action_job.rb
heya-0.2.0 lib/heya/campaigns/step_action_job.rb
heya-0.1.0 lib/heya/campaigns/step_action_job.rb