Module: Omnes::Subscriber::Adapter::Sidekiq

Extended by:
Configurable
Defined in:
lib/omnes/subscriber/adapter/sidekiq.rb

Overview

Sidekiq adapter

Builds subscription to be processed as Sidekiq's background jobs.

Sidekiq requires that the argument passed to #perform is serializable. By default, the result of calling #payload in the event is taken.

class MySubscriber
  include Omnes::Subscriber
  include Sidekiq::Job

  handle :my_event, with: Adapter::Sidekiq

  def perform(payload)
    # do_something
  end
end

bus = Omnes::Bus.new
bus.register(:my_event)
bus.publish(:my_event, "foo" => "bar")

However, you can configure how the event is serialized thanks to the serializer: option. It needs to be something callable taking the event as argument:

handle :my_event, with: Adapter::Sidekiq[serializer: :serialized_payload.to_proc]

You can also globally configure the default serializer:

Omnes.config.subscriber.adapter.sidekiq.serializer = :serialized_payload.to_proc

You can delay the callback execution from the publication time with the Sidekiq.in method (analogous to Sidekiq::Job.perform_in).

Examples:

handle :my_event, with: Adapter::Sidekiq.in(60)

Defined Under Namespace

Classes: Instance

Class Method Summary collapse

Class Method Details

.[](serializer: config.serializer) ⇒ Object

Parameters:

  • serializer (#call) (defaults to: config.serializer)


57
58
59
# File 'lib/omnes/subscriber/adapter/sidekiq.rb', line 57

def self.[](serializer: config.serializer)
  Instance.new(serializer: serializer)
end

.call(instance, event, publication_context) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



62
63
64
# File 'lib/omnes/subscriber/adapter/sidekiq.rb', line 62

def self.call(instance, event, publication_context)
  self.[].(instance, event, publication_context)
end

.configConfigurable::Config Originally defined in module Configurable

Returns the configuration class

Use this class to access readers and writers for the defined settings or nested configurations

.configure {|@config| ... } ⇒ Object Originally defined in module Configurable

Yields the configuration class

Yields:

See Also:

.in(seconds) ⇒ Object

Parameters:

  • seconds (Integer)


67
68
69
# File 'lib/omnes/subscriber/adapter/sidekiq.rb', line 67

def self.in(seconds)
  self.[].in(seconds)
end

.nest_config(constant, name: default_nesting_name(constant)) ⇒ Object Originally defined in module Configurable

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

.setting(name, default:) ⇒ Object Originally defined in module Configurable

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.