Sha256: abc3d006d6168ec3d8a6a8e516ffefa22ef1278a5926270c61d35aad34197719

Contents?: true

Size: 738 Bytes

Versions: 2

Compression:

Stored size: 738 Bytes

Contents

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

        def call
          retrieve_delays
          filter_crons
        end

        private

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

        def filter_crons
          @jobs.map! do |job|
            hash = JSON.parse(job.first).merge(perform_at: job.last)
            hash['cron'].empty? ? next : hash
          end
          @jobs.compact[@start, @count]
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
qpush-0.1.10 lib/qpush/web/apis/crons.rb
qpush-0.1.8 lib/qpush/web/apis/crons.rb