Sha256: 4fc38e99deb45b1807efc5fe6407580892a2d2e4efca3f4d05a7c6aefa73820c

Contents?: true

Size: 1.15 KB

Versions: 10

Compression:

Stored size: 1.15 KB

Contents

module Resque
  module Failure
    # A Failure backend that stores exceptions in Redis. Very simple but
    # works out of the box, along with support in the Resque web app.
    class Redis < Base
      def save
        data = {
          :failed_at => Time.now.strftime("%Y/%m/%d %H:%M:%S"),
          :payload   => payload,
          :exception => exception.class.to_s,
          :error     => exception.to_s,
          :backtrace => exception.backtrace,
          :worker    => worker.to_s,
          :queue     => queue
        }
        data = Resque.encode(data)
        Resque.redis.rpush(:failed, data)
      end

      def self.count
        Resque.redis.llen(:failed).to_i
      end

      def self.all(start = 0, count = 1)
        Resque.list_range(:failed, start, count)
      end
      
      def self.clear
        Resque.redis.del(:failed)
      end
      
      def self.requeue(index)
        item = all(index)
        item['retried_at'] = Time.now.strftime("%Y/%m/%d %H:%M:%S")
        Resque.redis.lset(:failed, index, Resque.encode(item))
        Job.create(item['queue'], item['payload']['class'], *item['payload']['args'])
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 2 rubygems

Version Path
resque-1.8.5 lib/resque/failure/redis.rb
resque-1.8.4 lib/resque/failure/redis.rb
resque-1.8.3 lib/resque/failure/redis.rb
opengotham_resque-1.8.2 lib/resque/failure/redis.rb
resque-1.8.2 lib/resque/failure/redis.rb
resque-1.8.1 lib/resque/failure/redis.rb
resque-1.8.0 lib/resque/failure/redis.rb
resque-1.7.1 lib/resque/failure/redis.rb
resque-1.7.0 lib/resque/failure/redis.rb
resque-1.6.1 lib/resque/failure/redis.rb