Merge pull request #36 from Retrospring/feature-delayed-ask-all

Delayed Ask All
This commit is contained in:
Yuki 2015-07-27 13:18:55 +05:30
commit 13798bd7fa
5 changed files with 43 additions and 11 deletions

View File

@ -55,16 +55,13 @@ 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 +70,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,14 +1,14 @@
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)
begin
User.find(resource_id).destroy!
rescue => e
Rails.logger.error "failed to delete user: #{e.message}"
logger.info "failed to delete user: #{e.message}"
end
end
end

View File

@ -0,0 +1,27 @@
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.groups.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}"
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
@ -11,8 +11,8 @@ class ShareWorker
begin
service.post(Answer.find(answer_id)) if services.include? service.provider
rescue => e
Rails.logger.error "failed to post answer #{answer_id} to #{service.provider} for user #{user_id}: #{e.message}"
logger.info "failed to post answer #{answer_id} to #{service.provider} for user #{user_id}: #{e.message}"
end
end
end
end
end

View File

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