2015-07-26 23:59:56 -07:00
|
|
|
class QuestionWorker
|
|
|
|
include Sidekiq::Worker
|
|
|
|
|
|
|
|
sidekiq_options queue: :question, retry: false
|
|
|
|
|
2015-07-27 00:42:00 -07:00
|
|
|
# @param rcpt [String] recipient
|
2015-07-27 00:12:12 -07:00
|
|
|
# @param user_id [Integer] user id passed from Devise
|
|
|
|
# @param question_id [Integer] newly created question id
|
2015-07-26 23:59:56 -07:00
|
|
|
def perform(rcpt, user_id, question_id)
|
|
|
|
begin
|
|
|
|
user = User.find(user_id)
|
2015-07-27 00:12:12 -07:00
|
|
|
if rcpt == 'followers'
|
2015-07-26 23:59:56 -07:00
|
|
|
user.followers.each do |f|
|
2015-07-27 00:46:26 -07:00
|
|
|
Inbox.create(user_id: f.id, question_id: question_id, new: true)
|
2015-07-26 23:59:56 -07:00
|
|
|
end
|
2015-07-27 00:12:12 -07:00
|
|
|
elsif rcpt.start_with? 'grp:'
|
2015-07-27 00:42:00 -07:00
|
|
|
user.groups.find_by_name!(rcpt.sub 'grp:', '').members.each do |m|
|
2015-07-27 00:46:26 -07:00
|
|
|
Inbox.create(user_id: m.user.id, question_id: question_id, new: true)
|
2015-07-26 23:59:56 -07:00
|
|
|
end
|
2015-07-27 00:42:00 -07:00
|
|
|
else
|
|
|
|
logger.info "unknown rcpt #{rcpt}"
|
2015-07-26 23:59:56 -07:00
|
|
|
end
|
|
|
|
rescue => e
|
2015-07-27 00:18:10 -07:00
|
|
|
logger.info "failed to ask question: #{e.message}"
|
2017-03-31 14:17:36 -07:00
|
|
|
Rollbar.error(e)
|
2015-07-26 23:59:56 -07:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|