Class: Procrastinate::Proxy

Inherits:
Object
  • Object
show all
Defined in:
lib/procrastinate/proxy.rb

Overview

A proxy class that will translate all method calls made on it to method calls inside their own process via the Scheduler.

Instance Method Summary collapse

Constructor Details

#initialize(worker, scheduler) ⇒ Proxy

Create a new proxy class. worker is an instance of the class that we want to perform work in, scheduler is where the work will be scheduled. Don’t call this on your own, instead use Scheduler#proxy.



9
10
11
12
# File 'lib/procrastinate/proxy.rb', line 9

def initialize(worker, scheduler) # :nodoc: 
  @worker = worker
  @scheduler = scheduler
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/procrastinate/proxy.rb', line 18

def method_missing(name, *args, &block)
  if respond_to? name
    task = Procrastinate::Task::Callable.new(
      lambda { @worker.send(name, *args, &block) })
    @scheduler.schedule(task)
    
    return task.result
  else
    super
  end
end

Instance Method Details

#respond_to?(name) ⇒ Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/procrastinate/proxy.rb', line 14

def respond_to?(name)
  @worker.respond_to?(name)
end