Module: ResqueRetry::Server::Helpers

Defined in:
lib/resque-retry/server.rb

Overview

Helper methods used by retry tab.

Instance Method Summary collapse

Instance Method Details

#cancel_retry(job) ⇒ Object

cancels job retry



76
77
78
79
80
81
82
83
84
85
86
# File 'lib/resque-retry/server.rb', line 76

def cancel_retry(job)
  klass = get_class(job)
  if klass
    retry_key = retry_key_for_job(job)
    Resque.remove_delayed(klass, *job['args'])
    Resque.redis.del("failure-#{retry_key}")
    Resque.redis.del(retry_key)
  else
    raise 'cannot cancel, job not found'
  end
end

#local_template(path) ⇒ Object

reads a ‘local’ template file.



70
71
72
73
# File 'lib/resque-retry/server.rb', line 70

def local_template(path)
  # Is there a better way to specify alternate template locations with sinatra?
  File.read(File.join(File.dirname(__FILE__), "server/views/#{path}"))
end

#retry_attempts_for_job(job) ⇒ Object

gets the number of retry attempts for a job.



51
52
53
54
55
56
57
58
# File 'lib/resque-retry/server.rb', line 51

def retry_attempts_for_job(job)
  retry_key = retry_key_for_job(job)
  if retry_key
    Resque.redis.get(retry_key)
  else
    nil
  end
end

#retry_failure_details(retry_key) ⇒ Object

gets the failure details hash for a job.



61
62
63
64
65
66
67
# File 'lib/resque-retry/server.rb', line 61

def retry_failure_details(retry_key)
  if retry_key
    Resque.decode(Resque.redis.get("failure-#{retry_key}"))
  else
    nil
  end
end

#retry_key_for_job(job) ⇒ Object

builds a retry key for the specified job.



41
42
43
44
45
46
47
48
# File 'lib/resque-retry/server.rb', line 41

def retry_key_for_job(job)
  klass = get_class(job)
  if klass.respond_to?(:redis_retry_key)
    klass.redis_retry_key(job['args'])
  else
    nil
  end
end