Sha256: 7855105244434fd308333a0d1eecce2b35826d44fc6fc88cd2699a0d94653e10

Contents?: true

Size: 1.14 KB

Versions: 15

Compression:

Stored size: 1.14 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 => Array(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

15 entries across 15 versions & 1 rubygems

Version Path
resque-1.13.0 lib/resque/failure/redis.rb
resque-1.11.0 lib/resque/failure/redis.rb
resque-1.12.0 lib/resque/failure/redis.rb
resque-1.10.0 lib/resque/failure/redis.rb
resque-1.9.10 lib/resque/failure/redis.rb
resque-1.9.9 lib/resque/failure/redis.rb
resque-1.9.8 lib/resque/failure/redis.rb
resque-1.9.7 lib/resque/failure/redis.rb
resque-1.9.5 lib/resque/failure/redis.rb
resque-1.9.4 lib/resque/failure/redis.rb
resque-1.9.3 lib/resque/failure/redis.rb
resque-1.9.2 lib/resque/failure/redis.rb
resque-1.9.1 lib/resque/failure/redis.rb
resque-1.9.0 lib/resque/failure/redis.rb
resque-1.8.6 lib/resque/failure/redis.rb