Allow retries for ShareWorker
This commit is contained in:
parent
61c8208e26
commit
f28f714457
|
@ -48,7 +48,9 @@ class Ajax::AnswerController < AjaxController
|
||||||
end
|
end
|
||||||
|
|
||||||
services = JSON.parse params[:share]
|
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
|
@response[:status] = :okay
|
||||||
|
|
|
@ -1,19 +1,19 @@
|
||||||
class ShareWorker
|
class ShareWorker
|
||||||
include Sidekiq::Worker
|
include Sidekiq::Worker
|
||||||
|
|
||||||
sidekiq_options queue: :share, retry: false
|
sidekiq_options queue: :share, retry: 5
|
||||||
|
|
||||||
# @param user_id [Integer] the user id
|
# @param user_id [Integer] the user id
|
||||||
# @param answer_id [Integer] the user id
|
# @param answer_id [Integer] the user id
|
||||||
# @param services [Array] array containing strings
|
# @param service [String] the service to post to
|
||||||
def perform(user_id, answer_id, services)
|
def perform(user_id, answer_id, service)
|
||||||
User.find(user_id).services.each do |service|
|
service_type = "Services::#{service.camelize}"
|
||||||
begin
|
user_service = User.find(user_id).services.find_by(type: service_type)
|
||||||
service.post(Answer.find(answer_id)) if services.include? service.provider
|
|
||||||
|
user_service.post(Answer.find(answer_id))
|
||||||
rescue => e
|
rescue => e
|
||||||
logger.info "failed to post answer #{answer_id} to #{service.provider} for user #{user_id}: #{e.message}"
|
logger.info "failed to post answer #{answer_id} to #{service.provider} for user #{user_id}: #{e.message}"
|
||||||
NewRelic::Agent.notice_error(e)
|
NewRelic::Agent.notice_error(e)
|
||||||
end
|
raise
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue