2020-05-25 09:33:09 -07:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
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 user_id [Integer] user id passed from Devise
|
|
|
|
# @param question_id [Integer] newly created question id
|
2020-05-25 09:33:09 -07:00
|
|
|
def perform(user_id, question_id)
|
|
|
|
user = User.find(user_id)
|
2021-12-22 10:21:09 -08:00
|
|
|
question = Question.find(question_id)
|
2020-05-25 09:33:09 -07:00
|
|
|
|
|
|
|
user.followers.each do |f|
|
2022-11-12 02:58:20 -08:00
|
|
|
next if f.banned?
|
2022-01-24 13:46:11 -08:00
|
|
|
next if MuteRule.where(user: f).any? { |rule| rule.applies_to? question }
|
|
|
|
|
|
|
|
Inbox.create(user_id: f.id, question_id: question_id, new: true)
|
2015-07-26 23:59:56 -07:00
|
|
|
end
|
2020-05-25 09:33:09 -07:00
|
|
|
rescue StandardError => e
|
|
|
|
logger.info "failed to ask question: #{e.message}"
|
2021-12-28 09:32:03 -08:00
|
|
|
Sentry.capture_exception(e)
|
2015-07-26 23:59:56 -07:00
|
|
|
end
|
|
|
|
end
|