Sha256: faebdebff5e2d6b06b9666f4a464881b0ccda5809d8362ef5396e1cd063fbbf0

Contents?: true

Size: 804 Bytes

Versions: 2

Compression:

Stored size: 804 Bytes

Contents

module QPush
  module Server
    module Apis
      # The Delay API will take a job and add it to the delay sorted set.
      #
      class Delay < Base
        def initialize(job, type)
          @job = job
          @type = type
        end

        def call
          load_type
          delay_job
        end

        private

        def delay_job
          Server.redis do |conn|
            conn.hincrby(Server.keys[:stats], @stat, 1)
            conn.zadd(Server.keys[:delay], @time, @job.to_json)
          end
        end

        def load_type
          case @type
          when :delay
            @stat = 'delayed'
            @time = @job.delay_until
          when :retry
            @stat = 'retries'
            @time = @job.retry_at
          end
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
qpush-0.1.10 lib/qpush/server/apis/delay.rb
qpush-0.1.8 lib/qpush/server/apis/delay.rb