Retrospring/app/workers/question_worker.rb

29 lines
879 B
Ruby
Raw Normal View History

class QuestionWorker
include Sidekiq::Worker
sidekiq_options queue: :question, retry: false
2015-07-27 00:42:00 -07:00
# @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|
2015-07-27 00:46:26 -07:00
Inbox.create(user_id: f.id, question_id: question_id, new: true)
end
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)
end
2015-07-27 00:42:00 -07:00
else
logger.info "unknown rcpt #{rcpt}"
end
rescue => e
2015-07-27 00:18:10 -07:00
logger.info "failed to ask question: #{e.message}"
2020-04-19 08:15:08 -07:00
NewRelic::Agent.notice_error(e)
end
end
end