Sha256: c09cdc4b839415d0de680f7bf95882472d8379e492d8ff714d5dd3b5fcc7c887

Contents?: true

Size: 713 Bytes

Versions: 1

Compression:

Stored size: 713 Bytes

Contents

require 'iron_mq'

class Fanforce::Workers

  def initialize(opts={})
    @opts = opts
  end

  def iron
    require_relative 'iron'
    @iron ||= Fanforce::Workers::Iron.new(@opts)
  end

  def self.enqueue(queue_id, payload)
    self.new.enqueue(queue_id, payload)
  end

  def enqueue(queue_id, payload)
    raise 'Payload being sent to the queue must be a Hash' if !payload.is_a?(Hash)
    iron.enqueue queue_id, params: payload, retries: 0
  end

  def retry_error(queue_id, msg_id)
    msg = iron.client.queue(queue_id + '-ERRORS').get(msg_id)
    data = MultiJson.load(msg.body, :symbolize_keys => true)
    iron.enqueue queue_id, params: data[:params], retries: data[:params] + 1
    msg.delete
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fanforce-workers-0.4.3 lib/fanforce/workers/workers.rb