Module: Resque::Plugins::Result

Defined in:
lib/resque/plugins/result.rb,
lib/resque/plugins/result/version.rb

Overview

If you want to be able fetch the result from a Resque job’s perform method. Results will be encoded using JSON.

For example:

require 'resque-result'

class MyJob
  extend Resque::Plugins::Result

  def self.perform(meta_id, big_num)
    factor(big_num)
  end
end

meta0 = MyJob.enqueue(3574406403731)
meta0.enqueued_at # => 'Wed May 19 13:42:41 -0600 2010'
meta0.meta_id # => '03c9e1a045ad012dd20500264a19273c'

# later
meta1 = MyJob.get_meta('03c9e1a045ad012dd20500264a19273c')
meta1.succeeded? # => true
meta1.result # => [ 1299709, 2750159 ]

Defined Under Namespace

Modules: Metadata

Constant Summary collapse

Version =
'1.0.1'

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(mod) ⇒ Object



31
32
33
34
# File 'lib/resque/plugins/result.rb', line 31

def self.extended(mod)
  mod.extend(Resque::Plugins::Meta)
  Resque::Plugins::Meta::Metadata.send(:include, Resque::Plugins::Result::Metadata)
end

Instance Method Details

#around_perform_meta_result(meta_id, *args) ⇒ Object



36
37
38
39
40
41
42
43
# File 'lib/resque/plugins/result.rb', line 36

def around_perform_meta_result(meta_id, *args)
  if meta = get_meta(meta_id)
    meta.result = yield
    meta.save
  else
    yield
  end
end