2014-12-12 23:45:49 +01:00
|
|
|
class ShareWorker
|
|
|
|
include Sidekiq::Worker
|
|
|
|
|
2021-12-25 13:40:21 +01:00
|
|
|
sidekiq_options queue: :share, retry: 5
|
2014-12-12 23:45:49 +01:00
|
|
|
|
2014-12-27 17:33:49 +01:00
|
|
|
# @param user_id [Integer] the user id
|
|
|
|
# @param answer_id [Integer] the user id
|
2021-12-25 13:40:21 +01:00
|
|
|
# @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))
|
2021-12-27 17:44:42 +01:00
|
|
|
rescue ActiveRecord::RecordNotFound
|
|
|
|
# The question to be posted was deleted
|
|
|
|
return
|
|
|
|
rescue Twitter::Error::DuplicateStatus
|
|
|
|
return
|
|
|
|
rescue Twitter::Error::Unauthorized
|
|
|
|
# User's Twitter token has expired or been revoked
|
|
|
|
# TODO: Notify user if this happens (https://github.com/Retrospring/retrospring/issues/123)
|
|
|
|
return
|
2021-12-25 13:40:21 +01:00
|
|
|
rescue => e
|
2021-12-25 23:22:52 +01:00
|
|
|
logger.info "failed to post answer #{answer_id} to #{service} for user #{user_id}: #{e.message}"
|
2021-12-25 13:40:21 +01:00
|
|
|
NewRelic::Agent.notice_error(e)
|
|
|
|
raise
|
2014-12-12 23:45:49 +01:00
|
|
|
end
|
2015-07-27 08:59:56 +02:00
|
|
|
end
|