Sha256: 14f0e764b87ccae4a3b634f5892412a889af616154fffa814e540a7e1dbefe14

Contents?: true

Size: 836 Bytes

Versions: 1

Compression:

Stored size: 836 Bytes

Contents

module QPush
  module Web
    module Apis
      class Retries
        def initialize(start, count)
          @start = start ? start.to_i : 0
          @count = count ? count.to_i : 10
          @jobs = nil
        end

        def call
          retrieve_jobs
          update_jobs
          trim_jobs
        end

        private

        def retrieve_jobs
          @jobs = Web.redis do |conn|
            conn.zrange(Web.keys.delay, 0, -1, with_scores: true)
          end
        end

        def update_jobs
          @jobs.map! do |job|
            hash = JSON.parse(job.first, symbolize_names: true).merge(perform_at: job.last)
            next unless hash[:failed]
            hash
          end
        end

        def trim_jobs
          @jobs.compact!
          @jobs[@start, @count]
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
qpush-0.1.7 lib/qpush/web/apis/retries.rb