Module: Resque::Plugins::Status::ClassMethods

Defined in:
lib/resque/plugins/status.rb

Instance Method Summary collapse

Instance Method Details

#create(options = {}) ⇒ Object

Create is the primary method for adding jobs to the queue. This would be called on the job class to create a job of that type. Any options passed are passed to the Job instance as a hash of options. It returns the UUID of the job.

Example:

class ExampleJob
  include Resque::Plugins::Status

  def perform
    set_status "Hey I'm a job num #{options['num']}"
  end

end

job_id = ExampleJob.create(:num => 100)


77
78
79
# File 'lib/resque/plugins/status.rb', line 77

def create(options = {})
  self.enqueue(self, options)
end

#enqueue(klass, options = {}) ⇒ Object

Adds a job of type <tt>klass<tt> to the queue with <tt>options<tt>. Returns the UUID of the job



83
84
85
86
87
# File 'lib/resque/plugins/status.rb', line 83

def enqueue(klass, options = {})
  uuid = Resque::Plugins::Status::Hash.create :options => options
  Resque.enqueue(klass, uuid, options)
  uuid
end

#nameObject

used when displaying the Job in the resque-web UI and identifiyng the job type by status. By default this is the name of the job class, but can be ovveridden in the specific job class to present a more user friendly job name



55
56
57
# File 'lib/resque/plugins/status.rb', line 55

def name
  self.to_s
end

#perform(uuid = nil, options = {}) ⇒ Object

This is the method called by Resque::Worker when processing jobs. It creates a new instance of the job class and populates it with the uuid and options.

You should not override this method, rahter the perform instance method.



94
95
96
97
98
99
# File 'lib/resque/plugins/status.rb', line 94

def perform(uuid=nil, options = {})
  uuid ||= Resque::Plugins::Status::Hash.generate_uuid
  instance = new(uuid, options)
  instance.safe_perform!
  instance
end

#queueObject

The default queue is :statused, this can be ovveridden in the specific job class to put the jobs on a specific worker queue



47
48
49
# File 'lib/resque/plugins/status.rb', line 47

def queue
  :statused
end

#scheduled(queue, klass, *args) ⇒ Object

Wrapper API to forward a Resque::Job creation API call into a Resque::Plugins::Status call. This is needed to be used with resque scheduler github.com/bvandenbos/resque-scheduler



104
105
106
# File 'lib/resque/plugins/status.rb', line 104

def scheduled(queue, klass, *args)
  create(*args)
end