Allow retries for ShareWorker
This commit is contained in:
parent
61c8208e26
commit
f28f714457
|
@ -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
|
||||
|
|
|
@ -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
|
||||
# @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)
|
||||
end
|
||||
end
|
||||
raise
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue