Class: Backburner::AsyncProxy

Inherits:
BasicObject
Defined in:
lib/backburner/async_proxy.rb

Overview

Class allows async task to be proxied

Instance Method Summary collapse

Constructor Details

#initialize(klazz, id = nil, opts = {}) ⇒ AsyncProxy

Options include ‘pri` (priority), `delay` (delay in secs), `ttr` (time to respond)

Examples:

AsyncProxy.new(User, 10, :pri => 1000, :ttr => 1000)


16
17
18
# File 'lib/backburner/async_proxy.rb', line 16

def initialize(klazz, id=nil, opts={})
  @klazz, @id, @opts = klazz, id, opts
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object

Enqueue as job when a method is invoked



21
22
23
# File 'lib/backburner/async_proxy.rb', line 21

def method_missing(method, *args, &block)
  ::Backburner::Worker.enqueue(@klazz, [@id, method, *args], @opts)
end