retrospring/app/workers/question_worker.rb
Georg Gadinger ea0685136e Rename Groups to Lists
haha regexp go brrr

special thanks to @seatsea for helping me out with the French locales
2020-05-25 18:04:54 +02:00

28 lines
878 B
Ruby

class QuestionWorker
include Sidekiq::Worker
sidekiq_options queue: :question, retry: false
# @param rcpt [String] recipient
# @param user_id [Integer] user id passed from Devise
# @param question_id [Integer] newly created question id
def perform(rcpt, user_id, question_id)
begin
user = User.find(user_id)
if rcpt == 'followers'
user.followers.each do |f|
Inbox.create(user_id: f.id, question_id: question_id, new: true)
end
elsif rcpt.start_with? 'grp:'
user.lists.find_by_name!(rcpt.sub 'grp:', '').members.each do |m|
Inbox.create(user_id: m.user.id, question_id: question_id, new: true)
end
else
logger.info "unknown rcpt #{rcpt}"
end
rescue => e
logger.info "failed to ask question: #{e.message}"
NewRelic::Agent.notice_error(e)
end
end
end