Module: ResqueJob

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object

:nodoc:



4
5
6
# File 'lib/resque_job.rb', line 4

def self.included(base) # :nodoc:
  base.extend ClassMethods
end

Instance Method Details

#result_keyObject



69
70
71
# File 'lib/resque_job.rb', line 69

def result_key
  @result_key ||= self.class.result_key(job_id)
end

#store_initial_result(res, options = {}) ⇒ Object



73
74
75
76
# File 'lib/resque_job.rb', line 73

def store_initial_result(res, options = {})
  key = self.class.result_key(options[:initial_job_id].presence || job_id)
  Resque.redis.set(key, res.to_json, ex: 1.hour.to_i)
end

#store_result(res, options = {}) ⇒ Object



78
79
80
81
82
83
84
85
86
# File 'lib/resque_job.rb', line 78

def store_result(res, options = {})
  key = if (jid = options[:initial_job_id]).blank?
          result_key
        else
          # store result with parent job id to retrieve the result later knowing only parent job id
          [Resque.redis.namespace, 'result', self.class.name.underscore, jid, job_id].join(':')
        end
  Resque.redis.set(key, res.to_json, ex: 1.hour.to_i)
end