Sha256: 5c64e828ecd85f43d445fbadd677600bd951ba9e5fba9f9166b6184671f45274

Contents?: true

Size: 930 Bytes

Versions: 1

Compression:

Stored size: 930 Bytes

Contents

module PubsubNotifier
  module Broadcasters
    class ActiveJobBroadcaster < Base
      def broadcast(subscriber, publisher, event, args)
        configured_job.perform_later(subscriber.name, event, args)
      rescue ActiveJob::SerializationError => e
        # NOTE: Fallback if global_id is blank
        logger.warn { e.inspect }
        configured_job.perform_now(subscriber.name, event, *args)
      end

      private

        def configured_job
          BroadcastJob.set(options)
        end

        def default_options
          { wait: nil, wait_until: nil, queue: :default }
        end

      class BroadcastJob < ::ActiveJob::Base
        def perform(subscriber_name, event, args)
          subscriber = subscriber_name.constantize
          subscriber.public_send(event, *args)
        end
      end
    end
  end
end

PubsubNotifier.register_broadcaster :async, PubsubNotifier::Broadcasters::ActiveJobBroadcaster

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pubsub_notifier-0.1.0 lib/pubsub_notifier/broadcasters/active_job_broadcaster.rb