Sha256: b8af3d076c327df781c4558f32359e4465d2c7464f9016f4e0b9ebdde07f8f68

Contents?: true

Size: 950 Bytes

Versions: 1

Compression:

Stored size: 950 Bytes

Contents

require 'activehook/workers/base'

module ActiveHook
  module Workers
    class Retry < Base
      def start
        until @done
          retries = retrieve_retries
          update(retries) unless retries.empty?
          sleep 2
        end
      end

      private

      def retrieve_retries
        ActiveHook.redis.with do |conn|
          conn.zrangebyscore('ah:retry', 0, Time.now.to_i)
        end
      end

      def update(retries)
        ActiveHook.redis.with do |conn|
          conn.pipelined do
            conn.zrem('ah:retry', retries)
            conn.incrby('ah:total_retries', retries.count)
          end
        end
        retries.each { |r| RetryRunner.new(r) }
      end
    end

    class RetryRunner
      def initialize(json)
        @json = json
        @hook = ActiveHook::Hook.new(JSON.parse(@json))
        start
      end

      def start
        @hook.bump_retry
        @hook.perform
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
activehook-0.1.0 lib/activehook/workers/retry.rb