mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 22:43:33 +08:00
FIX: Processing incoming email should be done in a background job.
This commit is contained in:
@ -84,8 +84,8 @@ class Admin::EmailController < Admin::AdminController
|
|||||||
|
|
||||||
def handle_mail
|
def handle_mail
|
||||||
params.require(:email)
|
params.require(:email)
|
||||||
Email::Processor.process!(params[:email])
|
Jobs.enqueue(:process_email, mail: params[:email], retry_on_rate_limit: true)
|
||||||
render plain: "email was processed"
|
render plain: "email has been received and is queued for processing"
|
||||||
end
|
end
|
||||||
|
|
||||||
def raw_email
|
def raw_email
|
||||||
|
@ -4,7 +4,7 @@ module Jobs
|
|||||||
sidekiq_options retry: 3
|
sidekiq_options retry: 3
|
||||||
|
|
||||||
def execute(args)
|
def execute(args)
|
||||||
Email::Processor.process!(args[:mail], false)
|
Email::Processor.process!(args[:mail], args[:retry_on_rate_limit] || false)
|
||||||
end
|
end
|
||||||
|
|
||||||
sidekiq_retries_exhausted do |msg|
|
sidekiq_retries_exhausted do |msg|
|
||||||
|
@ -553,7 +553,7 @@ module Email
|
|||||||
def create_post_with_attachments(options={})
|
def create_post_with_attachments(options={})
|
||||||
# deal with attachments
|
# deal with attachments
|
||||||
attachments.each do |attachment|
|
attachments.each do |attachment|
|
||||||
tmp = Tempfile.new("discourse-email-attachment")
|
tmp = Tempfile.new(["discourse-email-attachment", File.extname(attachment.filename)])
|
||||||
begin
|
begin
|
||||||
# read attachment
|
# read attachment
|
||||||
File.open(tmp.path, "w+b") { |f| f.write attachment.body.decoded }
|
File.open(tmp.path, "w+b") { |f| f.write attachment.body.decoded }
|
||||||
|
@ -71,4 +71,16 @@ describe Admin::EmailController do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context '#handle_mail' do
|
||||||
|
before do
|
||||||
|
log_in_user(Fabricate(:admin))
|
||||||
|
SiteSetting.queue_jobs = true
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should enqueue the right job' do
|
||||||
|
expect { xhr :post, :handle_mail, email: email('cc') }
|
||||||
|
.to change { Jobs::ProcessEmail.jobs.count }.by(1)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -232,6 +232,4 @@ describe EmailController do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
Reference in New Issue
Block a user