class Ryespy::Notifier::Sidekiq

Constants

SIDEKIQ_KEY_QUEUES
SIDEKIQ_KEY_QUEUE_X
SIDEKIQ_QUEUE

Public Class Methods

new(opts = {}) { |self| ... } click to toggle source
# File lib/ryespy/notifier/sidekiq.rb, line 16
def initialize(opts = {})
  @redis_config = {
    :url       => opts[:url],
    :namespace => opts[:namespace],
  }
  
  @logger = opts[:logger] || Logger.new(nil)
  
  connect_redis
  
  if block_given?
    yield self
    
    close
  end
end

Public Instance Methods

close() click to toggle source
# File lib/ryespy/notifier/sidekiq.rb, line 33
def close
  @redis.quit
end
notify(job_class, args) click to toggle source
# File lib/ryespy/notifier/sidekiq.rb, line 37
def notify(job_class, args)
  @redis.sadd(SIDEKIQ_KEY_QUEUES, SIDEKIQ_QUEUE)
  
  sidekiq_job_payload = sidekiq_job(job_class, args)
  
  @logger.debug { "Setting Redis Key #{SIDEKIQ_KEY_QUEUE_X} Payload #{sidekiq_job_payload.to_json}" }
  
  @redis.rpush(SIDEKIQ_KEY_QUEUE_X, sidekiq_job_payload.to_json)
end

Private Instance Methods

connect_redis() click to toggle source
# File lib/ryespy/notifier/sidekiq.rb, line 49
def connect_redis
  @redis = Redis::Namespace.new(@redis_config[:namespace],
    :redis => Redis.connect(:url => @redis_config[:url])
  )
end
sidekiq_job(job_class, args) click to toggle source
# File lib/ryespy/notifier/sidekiq.rb, line 55
def sidekiq_job(job_class, args)
  {
    # resque
    :class => job_class,
    :args  => args,
    # sidekiq (extra)
    :queue => SIDEKIQ_QUEUE,
    :retry => true,
    :jid   => SecureRandom.hex(12),
  }
end