Class: SidekiqPublisher
- Inherits:
-
Object
- Object
- SidekiqPublisher
- Defined in:
- lib/sidekiq_publisher.rb
Instance Method Summary collapse
- #configure_sidekiq_server ⇒ Object
- #get_delay_time(current_retry_attempt) ⇒ Object
-
#initialize ⇒ SidekiqPublisher
constructor
A new instance of SidekiqPublisher.
- #publish_to_sidekiq(topic, message) ⇒ Object
Constructor Details
#initialize ⇒ SidekiqPublisher
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_server ⇒ Object
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, ) configure_sidekiq_server delay_time = get_delay_time(['current_retry_attempt']) FailedEventDelayedRetryWorker.set(queue: @configs['sidekiq_queue']).perform_in(delay_time.minutes, topic, ) end |