Class: Sidekiqable::AsyncProxy
- Inherits:
-
Object
- Object
- Sidekiqable::AsyncProxy
- Defined in:
- lib/sidekiqable/async_proxy.rb
Instance Method Summary collapse
-
#initialize(target_class, mode, schedule_arg = nil) ⇒ AsyncProxy
constructor
A new instance of AsyncProxy.
- #method_missing(method_name, *args, &block) ⇒ Object
- #respond_to_missing?(method_name, include_private = false) ⇒ Boolean
Constructor Details
#initialize(target_class, mode, schedule_arg = nil) ⇒ AsyncProxy
Returns a new instance of AsyncProxy.
5 6 7 8 9 |
# File 'lib/sidekiqable/async_proxy.rb', line 5 def initialize(target_class, mode, schedule_arg = nil) @target_class = target_class @mode = mode @schedule_arg = schedule_arg end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/sidekiqable/async_proxy.rb', line 11 def method_missing(method_name, *args, &block) raise Sidekiqable::Error, "Cannot enqueue blocks to Sidekiq" if block super unless i[perform_async perform_in perform_at].include?(@mode) validate_serializable!(method_name, args) if Sidekiqable.configuration.validate_arguments worker_class = Sidekiqable::Worker worker = apply_config(worker_class) callable = "#{@target_class.name}.#{method_name}" payload = [callable, *args] case @mode when :perform_async worker.perform_async(*payload) when :perform_in worker.perform_in(@schedule_arg, *payload) when :perform_at worker.perform_at(@schedule_arg, *payload) end end |
Instance Method Details
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
34 35 36 |
# File 'lib/sidekiqable/async_proxy.rb', line 34 def respond_to_missing?(method_name, include_private = false) @target_class.respond_to?(method_name, include_private) end |