Module: Updater::Target

Defined in:
lib/updater/target.rb

Overview

By including this module in a client’s classes, it is possible to schedule jobs with the

inlcuded methods.  This saves typing `Updater::Update.[in|at|immidate] `repeatedly.
The class also allows you to set special finder and ID methods on a per class basis.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(model) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/updater/target.rb', line 7

def self.included(model)
  model.class_eval do
    class << self
      
      # This will overide the default finder for Update and the chosen ORM. Set
      # it the symbol of a class method that can find/instantiate instances of the class.
      # It will be passed the value returned from the ID method called on an 
      # instance.  The ID method can be overridden as well.  See +updater_id_method+
      attr_accessor :updater_finder_method
      
      # This will overide the ID method set in both with Update and the chosen ORM.
      # Set it to the symbol of an instance method.  The value of this method will be given
      # to the finder method in order to recreate the instance for the worker.  The finder
      # method can be overridden as well.  See +updater_finder_method+
      attr_accessor :updater_id_method
    end
  end
  
  super
end

Instance Method Details

#enqueue(*args) ⇒ Object Also known as: send_later

Place a job on the queue for immidiate execution. This method is aliased to ‘send_later` for compatibility with delayed_job. See Also Update#immidiate



41
42
43
# File 'lib/updater/target.rb', line 41

def enqueue(*args)
  Update.immidiate(self,*args)
end

#jobs_for(name = nil) ⇒ Object Also known as: job_for

Finds all the jobs whose target is this instance. If a name is given, it will return only the job with that name set. There can be only one job with a given name per unique target. Also note that jobs that have their finder or finder_args set on creation cannot be named and will not be found by this method. See aslo Update#for



33
34
35
# File 'lib/updater/target.rb', line 33

def jobs_for(name = nil)
  Update.for(self, name)
end

#send_at(time, *args) ⇒ Object

Put a job on the queue to run at a spesified time. See Also Update#at



48
49
50
# File 'lib/updater/target.rb', line 48

def send_at(time, *args)
  Update.at(time,self,*args)
end

#send_in(delta_seconds, *args) ⇒ Object

Put a job on the queue to run after a spesified duration (in seconds). See Also Update#in



53
54
55
# File 'lib/updater/target.rb', line 53

def send_in(delta_seconds,*args)
  Update.in(delta_seconds,self,*args)
end