diaspora/app/workers/send_base.rb
Jason Robinson 78299c9e2f Consolidate amount of sidekiq queues from 13 to 5
Sidekiq documentation says 'Sidekiq is not designed to work well with dozens of queues.'. Having the amount of queues we have at the moment brings no anyway.

Closes #5571
2016-08-10 08:51:22 +00:00

29 lines
775 B
Ruby

module Workers
class SendBase < Base
sidekiq_options queue: :medium, retry: 0
MAX_RETRIES = AppConfig.environment.sidekiq.retry.get.to_i
protected
def schedule_retry(retry_count, sender_id, obj_str, failed_urls)
if retry_count < MAX_RETRIES
yield(seconds_to_delay(retry_count), retry_count)
else
logger.warn "status=abandon sender=#{sender_id} obj=#{obj_str} failed_urls='[#{failed_urls.join(', ')}]'"
raise MaxRetriesReached
end
end
private
# based on Sidekiq::Middleware::Server::RetryJobs#seconds_to_delay
def seconds_to_delay(count)
((count + 3)**4) + (rand(30) * (count + 1))
end
# send job to the dead job queue
class MaxRetriesReached < RuntimeError
end
end
end