Class: Ryespy::Notifier::Sidekiq

Inherits:
Object
  • Object
show all
Defined in:
lib/ryespy/notifier/sidekiq.rb

Constant Summary collapse

SIDEKIQ_QUEUE =
'ryespy'.freeze
SIDEKIQ_KEY_QUEUES =
'queues'.freeze
SIDEKIQ_KEY_QUEUE_X =
"queue:#{SIDEKIQ_QUEUE}".freeze

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Sidekiq

Returns a new instance of Sidekiq.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# 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

Instance Method Details

#closeObject



33
34
35
# File 'lib/ryespy/notifier/sidekiq.rb', line 33

def close
  @redis.quit
end

#notify(job_class, args) ⇒ Object



37
38
39
40
41
42
43
44
45
# 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