2015-07-26 23:59:56 -07:00
|
|
|
class QuestionWorker
|
|
|
|
include Sidekiq::Worker
|
|
|
|
|
|
|
|
sidekiq_options queue: :question, retry: false
|
|
|
|
|
2015-07-27 00:12:12 -07:00
|
|
|
# @param rcpt [Integer] string recipient
|
|
|
|
# @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:12:12 -07:00
|
|
|
Inbox.create(user_id: fid, 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:'
|
|
|
|
current_user.groups.find_by_name!(rcpt.sub 'grp:', '').members.each do |m|
|
|
|
|
Inbox.create(user_id: m.user.id, question_id: question.id, new: true)
|
2015-07-26 23:59:56 -07:00
|
|
|
end
|
|
|
|
end
|
|
|
|
rescue => e
|
2015-07-27 00:12:12 -07:00
|
|
|
logger.error "failed to ask question: #{e.message}"
|
2015-07-26 23:59:56 -07:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|