Sha256: f5cc2c69fc72309e6050ebb565c3bf5a4ac79ab0a91e03eda2bd0d137938def5

Contents?: true

Size: 1.82 KB

Versions: 4

Compression:

Stored size: 1.82 KB

Contents

module Resque
  module Failure
    class MultipleFailure < 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_#{queue}".to_sym, data)
      end
      
      def self.queues
        Resque.queues.map {|queue| "failed_#{queue}"}
      end
      
      def self.count(queue=nil)
        if queue
          queue = queue =~ /^failed_/ ? queue : "failed_#{queue}"
          Resque.redis.llen(queue.to_sym).to_i
        else
          count = 0
          Resque.queues.each do |queue|
            count += Resque.redis.llen("failed_#{queue}".to_sym).to_i
          end
          count
        end
      end
      
      def self.url
        "/failed/list"
      end
      
      def self.all(queue, start = 0, count = 1)
        queue = queue =~ /^failed_/ ? queue : "failed_#{queue}"
        Resque.list_range(queue.to_sym, start, count)
      end

      def self.clear(queue=nil)
        if queue
          queue = queue =~ /^failed_/ ? queue : "failed_#{queue}"
          Resque.redis.del(queue.to_sym)
        else
          Resque.queues.each {|queue| Resque.redis.del("failed_#{queue}") }
        end
      end

      def self.requeue(queue, index)
        queue = queue =~ /^failed_/ ? queue : "failed_#{queue}"
        item = all(queue, index)
        item['retried_at'] = Time.now.strftime("%Y/%m/%d %H:%M:%S")
        Resque.redis.lset(queue.to_sym, index, Resque.encode(item))
        Job.create(item['queue'], item['payload']['class'], *item['payload']['args'])
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
resque-multiple-failure-backend-1.1.1 lib/resque/failure/multiple_failure.rb
resque-multiple-failure-backend-1.1.0 lib/resque/failure/multiple_failure.rb
resque-multiple-failure-backend-1.0.1 lib/resque/failure/multiple_failure.rb
resque-multiple-failure-backend-1.0.0 lib/resque/failure/multiple_failure.rb