FIX: Don't enqueue jobs in a transaction
This commit is contained in:
parent
2f68be2c5c
commit
2cb4cb7b72
|
@ -61,20 +61,23 @@ class QueuedPost < ActiveRecord::Base
|
|||
|
||||
def approve!(approved_by)
|
||||
created_post = nil
|
||||
|
||||
creator = PostCreator.new(user, create_options.merge(skip_validations: true, skip_jobs: true))
|
||||
QueuedPost.transaction do
|
||||
change_to!(:approved, approved_by)
|
||||
|
||||
UserBlocker.unblock(user, approved_by) if user.blocked?
|
||||
|
||||
creator = PostCreator.new(user, create_options.merge(skip_validations: true))
|
||||
created_post = creator.create
|
||||
|
||||
unless created_post && creator.errors.blank?
|
||||
raise StandardError.new(creator.errors.full_messages.join(" "))
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
# Do sidekiq work outside of the transaction
|
||||
creator.enqueue_jobs
|
||||
|
||||
DiscourseEvent.trigger(:approved_post, self)
|
||||
created_post
|
||||
end
|
||||
|
|
|
@ -145,7 +145,7 @@ class PostCreator
|
|||
publish
|
||||
|
||||
track_latest_on_category
|
||||
enqueue_jobs
|
||||
enqueue_jobs unless @opts[:skip_jobs]
|
||||
BadgeGranter.queue_badge_grant(Badge::Trigger::PostRevision, post: @post)
|
||||
|
||||
trigger_after_events(@post)
|
||||
|
@ -170,6 +170,11 @@ class PostCreator
|
|||
@post
|
||||
end
|
||||
|
||||
def enqueue_jobs
|
||||
return unless @post && !@post.errors.present?
|
||||
PostJobsEnqueuer.new(@post, @topic, new_topic?, {import_mode: @opts[:import_mode]}).enqueue_jobs
|
||||
end
|
||||
|
||||
def self.track_post_stats
|
||||
Rails.env != "test".freeze || @track_post_stats
|
||||
end
|
||||
|
@ -449,11 +454,6 @@ class PostCreator
|
|||
end
|
||||
end
|
||||
|
||||
def enqueue_jobs
|
||||
return unless @post && !@post.errors.present?
|
||||
PostJobsEnqueuer.new(@post, @topic, new_topic?, {import_mode: @opts[:import_mode]}).enqueue_jobs
|
||||
end
|
||||
|
||||
def new_topic?
|
||||
@opts[:topic_id].blank?
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue