Sha256: ef15161a2c0c5f228494557b36ffe6fd3945d53973e8a442d4110da9cf7ffd8c

Contents?: true

Size: 892 Bytes

Versions: 6

Compression:

Stored size: 892 Bytes

Contents

module ActiveHook
  module Server
    class Retry
      def initialize
        @done = false
      end

      def start
        until @done
          ActiveHook::Server.redis.with do |conn|
            conn.watch('ah:retry') do
              retries = retrieve_retries(conn)
              update_retries(conn, retries)
            end
          end
          sleep 2
        end
      end

      def shutdown
        @done = true
      end

      private

      def retrieve_retries(conn)
        conn.zrangebyscore('ah:retry', 0, Time.now.to_i)
      end

      def update_retries(conn, retries)
        if retries.any?
          conn.multi do |multi|
            multi.incrby('ah:total_retries', retries.count)
            multi.zrem('ah:retry', retries)
            multi.lpush('ah:queue', retries)
          end
        else
          conn.unwatch
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
activehook-server-0.1.5 lib/activehook/server/retry.rb
activehook-server-0.1.4 lib/activehook/server/retry.rb
activehook-server-0.1.3 lib/activehook/server/retry.rb
activehook-server-0.1.2 lib/activehook/server/retry.rb
activehook-server-0.1.1 lib/activehook/server/retry.rb
activehook-server-0.1.0 lib/activehook/server/retry.rb