Class: SidekiqPublisher

Inherits:
Object
  • Object
show all
Defined in:
lib/sidekiq_publisher.rb

Instance Method Summary collapse

Constructor Details

#initializeSidekiqPublisher

Returns a new instance of SidekiqPublisher.



5
6
7
# File 'lib/sidekiq_publisher.rb', line 5

def initialize
  @configs = YAML.load_file("#{Rails.root}/config/ruby_kafka_retry.yml")[Rails.env]
end

Instance Method Details

#configure_sidekiq_serverObject



9
10
11
12
13
14
15
16
# File 'lib/sidekiq_publisher.rb', line 9

def configure_sidekiq_server
  Sidekiq.configure_server do |config|
    config.redis = { url: 'redis://' + @configs['redis_host'] + ':' + @configs['redis_port'].to_s + '/' + @configs['redis_db'].to_s}
  end
  Sidekiq.configure_client do |config|
    config.redis = { url: 'redis://' + @configs['redis_host'] + ':' + @configs['redis_port'].to_s + '/' + @configs['redis_db'].to_s}
  end
end

#get_delay_time(current_retry_attempt) ⇒ Object



18
19
20
# File 'lib/sidekiq_publisher.rb', line 18

def get_delay_time(current_retry_attempt)
  2 ** current_retry_attempt
end

#publish_to_sidekiq(topic, message) ⇒ Object



22
23
24
25
26
# File 'lib/sidekiq_publisher.rb', line 22

def publish_to_sidekiq(topic, message)
  configure_sidekiq_server
  delay_time = get_delay_time(message['current_retry_attempt'])
  FailedEventDelayedRetryWorker.set(queue: @configs['sidekiq_queue']).perform_in(delay_time.minutes, topic, message)
end