Allow retries for ShareWorker

This commit is contained in:
Karina Kwiatek 2021-12-25 13:40:21 +01:00
parent 61c8208e26
commit f28f714457
2 changed files with 14 additions and 12 deletions

View File

@ -48,7 +48,9 @@ class Ajax::AnswerController < AjaxController
end
services = JSON.parse params[:share]
ShareWorker.perform_async(current_user.id, answer.id, services)
services.each do |service|
ShareWorker.perform_async(current_user.id, answer.id, service)
end
@response[:status] = :okay

View File

@ -1,19 +1,19 @@
class ShareWorker
include Sidekiq::Worker
sidekiq_options queue: :share, retry: false
sidekiq_options queue: :share, retry: 5
# @param user_id [Integer] the user id
# @param answer_id [Integer] the user id
# @param services [Array] array containing strings
def perform(user_id, answer_id, services)
User.find(user_id).services.each do |service|
begin
service.post(Answer.find(answer_id)) if services.include? service.provider
rescue => e
logger.info "failed to post answer #{answer_id} to #{service.provider} for user #{user_id}: #{e.message}"
NewRelic::Agent.notice_error(e)
end
end
# @param service [String] the service to post to
def perform(user_id, answer_id, service)
service_type = "Services::#{service.camelize}"
user_service = User.find(user_id).services.find_by(type: service_type)
user_service.post(Answer.find(answer_id))
rescue => e
logger.info "failed to post answer #{answer_id} to #{service.provider} for user #{user_id}: #{e.message}"
NewRelic::Agent.notice_error(e)
raise
end
end