Moved ask all + ask group to worker, validates user_id for ask person now

This commit is contained in:
Yuki 2015-07-27 12:29:56 +05:30
parent fcbfa6efdb
commit 92bbfef2df
5 changed files with 37 additions and 10 deletions

View File

@ -55,16 +55,12 @@ class Ajax::QuestionController < ApplicationController
if params[:rcpt] == 'followers'
unless current_user.nil?
current_user.followers.each do |f|
Inbox.create!(user_id: f.id, question_id: question.id, new: true)
end
QuestionWorker.perform_async params[:rcpt], current_user.id, question.id
end
elsif params[:rcpt].start_with? 'grp:'
unless current_user.nil?
begin
current_user.groups.find_by_name!(params[:rcpt].sub 'grp:', '').members.each do |m|
Inbox.create!(user_id: m.user.id, question_id: question.id, new: true)
end
current_user.groups.find_by_name!(params[:rcpt].sub 'grp:', '')
QuestionWorker.perform_async params[:rcpt], current_user.id, question.id
rescue ActiveRecord::RecordNotFound
@status = :not_found
@message = I18n.t('messages.question.create.not_found')
@ -73,6 +69,13 @@ class Ajax::QuestionController < ApplicationController
end
end
else
if User.find(params[:rcpt]).nil?
@status = :not_found
@message = I18n.t('messages.question.create.not_found')
@success = false
return
end
Inbox.create!(user_id: params[:rcpt], question_id: question.id, new: true)
end

View File

@ -1,7 +1,7 @@
class DeletionWorker
include Sidekiq::Worker
sidekiq_options queue: :deletion
sidekiq_options queue: :deletion, retry: false
# @param resource_id [Integer] user id passed from Devise
def perform(resource_id)

View File

@ -0,0 +1,23 @@
class QuestionWorker
include Sidekiq::Worker
sidekiq_options queue: :question, retry: false
# @param resource_id [Integer] user id passed from Devise
def perform(rcpt, user_id, question_id)
begin
user = User.find(user_id)
if params[:rcpt].start_with? 'grp:'
user.followers.each do |f|
Inbox.create!(user_id: fid, question_id: question_id, new: true)
end
else
current_user.groups.find_by_name!(params[:rcpt].sub 'grp:', '').members.each do |m|
Inbox.create!(user_id: m.user.id, question_id: question.id, new: true)
end
end
rescue => e
Rails.logger.error "failed to answer question: #{e.message}"
end
end
end

View File

@ -1,7 +1,7 @@
class ShareWorker
include Sidekiq::Worker
sidekiq_options queue: :share
sidekiq_options queue: :share, retry: false
# @param user_id [Integer] the user id
# @param answer_id [Integer] the user id
@ -15,4 +15,4 @@ class ShareWorker
end
end
end
end
end

View File

@ -11,3 +11,4 @@ production:
- mailer
- deletion
- rollbar
- question