Module: ResqueRetry::Server

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

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/resque-retry/server.rb', line 5

def self.included(base)
  base.class_eval {
    helpers do
      # builds a retry key for the specified job.
      def retry_key_for_job(job)
        klass = Resque.constantize(job['class'])
        if klass.respond_to?(:redis_retry_key)
          klass.redis_retry_key(job['args'])
        else
          nil
        end
      end

      # gets the number of retry attempts for a job.
      def retry_attempts_for_job(job)
        Resque.redis.get(retry_key_for_job(job))
      end
      
      # gets the failure details hash for a job.
      def retry_failure_details(retry_key)
        Resque.decode(Resque.redis["failure_#{retry_key}"])
      end

      # reads a 'local' template file.
      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
    end

    get '/retry' do
      erb local_template('retry.erb')
    end

    get '/retry/:timestamp' do
      erb local_template('retry_timestamp.erb')
    end
  }
end