DEV: use DB.after_commit instead of delaying the job

This commit is contained in:
Régis Hanol 2019-11-29 22:48:39 +01:00
parent 5ae570a088
commit 455147cabe
1 changed files with 6 additions and 4 deletions

View File

@ -257,10 +257,12 @@ after_initialize do
args[:old_trust_level] == TrustLevel[1]
if SiteSetting.discourse_narrative_bot_enabled && promoted_from_tl1
# NOTE: since the `user_promoted` event is triggered from inside a transaction
# we have to delay the job otherwise it might run before the transaction
# is commited and the user will be invisible to the job
Jobs.enqueue_in(1.minute, :send_advanced_tutorial_message, user_id: args[:user_id])
# The event 'user_promoted' is sometimes called from inside a transaction.
# Use this helper to ensure the job is enqueued after commit to prevent
# any race conditions.
DB.after_commit do
Jobs.enqueue(:send_advanced_tutorial_message, user_id: args[:user_id])
end
end
end
end