Commit d48249b2 authored by Gabriel Mazetto's avatar Gabriel Mazetto

Refactored Backoff strategy to a concern

parent b9d3f9a9
require 'active_support/concern'
module GeoDynamicBackoff
extend ActiveSupport::Concern
included do
sidekiq_options retry: 55
sidekiq_retry_in do |count|
count <= 30 ? linear_backoff_strategy(count) : geometric_backoff_strategy(count)
end
end
private
def linear_backoff_strategy(count)
rand(1..20) + count
end
def geometric_backoff_strategy(count)
# This strategy is based on the original one from sidekiq
count = count-30 # we must start counting after 30
(count ** 4) + 15 + (rand(30)*(count+1))
end
end
class GeoKeyChangeNotifyWorker
include Sidekiq::Worker
include GeoDynamicBackoff
sidekiq_options queue: :default, retry: 55
sidekiq_retry_in do |count|
count <= 30 ? linear_backoff_strategy(count) : geometric_backoff_strategy(count)
end
sidekiq_options queue: :default
def perform(key_id, key, action)
Geo::NotifyKeyChangeService.new(key_id, key, action).execute
end
private
def linear_backoff_strategy(count)
rand(1..20) + count
end
def geometric_backoff_strategy(count)
# This strategy is based on the original one from sidekiq
count = count-30 # we must start counting after 30
(count ** 4) + 15 + (rand(30)*(count+1))
end
end
class GeoKeyRefreshWorker
include Sidekiq::Worker
include GeoDynamicBackoff
sidekiq_options queue: :default, retry: 55
sidekiq_retry_in do |count|
count <= 30 ? linear_backoff_strategy(count) : geometric_backoff_strategy(count)
end
sidekiq_options queue: :default
def perform(key_id, key, action)
action = action.to_sym
......@@ -24,16 +21,4 @@ class GeoKeyRefreshWorker
fail "Invalid action: #{action}"
end
end
private
def linear_backoff_strategy(count)
rand(1..20) + count
end
def geometric_backoff_strategy(count)
# This strategy is based on the original one from sidekiq
count = count-30 # we must start counting after 30
(count ** 4) + 15 + (rand(30)*(count+1))
end
end
......@@ -19,7 +19,8 @@ module Gitlab
#{config.root}/app/models/hooks
#{config.root}/app/models/concerns
#{config.root}/app/models/project_services
#{config.root}/app/models/members))
#{config.root}/app/models/members
#{config.root}/app/workers/concerns))
# Only load the plugins named here, in the order given (default is alphabetical).
# :all can be used as a placeholder for all plugins not explicitly named.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment