2014-12-12 14:45:49 -08:00
class ShareWorker
include Sidekiq :: Worker
2021-12-25 04:40:21 -08:00
sidekiq_options queue : :share , retry : 5
2014-12-12 14:45:49 -08:00
2014-12-27 08:33:49 -08:00
# @param user_id [Integer] the user id
# @param answer_id [Integer] the user id
2021-12-25 04:40:21 -08: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 08:44:42 -08:00
rescue ActiveRecord :: RecordNotFound
2021-12-27 09:17:47 -08:00
logger . info " Tried to post answer # #{ answer_id } for user # #{ user_id } to #{ service . titleize } but the user/answer/service did not exist (likely deleted), will not retry. "
2021-12-27 08:44:42 -08:00
# The question to be posted was deleted
return
rescue Twitter :: Error :: DuplicateStatus
2021-12-27 14:03:51 -08:00
logger . info " Tried to post answer # #{ answer_id } from user # #{ user_id } to Twitter but the status was already posted. "
2021-12-27 08:44:42 -08:00
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)
2021-12-27 14:03:51 -08:00
logger . info " Tried to post answer # #{ answer_id } from user # #{ user_id } to Twitter but the token has exired or been revoked. "
2021-12-27 08:44:42 -08:00
return
2021-12-25 04:40:21 -08:00
rescue = > e
2021-12-25 14:22:52 -08:00
logger . info " failed to post answer #{ answer_id } to #{ service } for user #{ user_id } : #{ e . message } "
2021-12-28 09:32:03 -08:00
Sentry . capture_exception ( e )
2021-12-25 04:40:21 -08:00
raise
2014-12-12 14:45:49 -08:00
end
2015-07-26 23:59:56 -07:00
end