mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 10:57:04 +08:00
FIX: delay the 'send_advanced_tutorial_message' job to prevent race conditions
When a user accepts an invite with an email address that matches a group which automatically awards its members Trust Level 2, a race condition might happen when the 'send_advanced_tutorial_message' job runs. That job is enqueued inside the 'user_promoted' event which is triggered inside a transaction on the user record. If the job runs before the transaction is done, the user record is invisible and this generates an exception.
This commit is contained in:
parent
06c2e28bbb
commit
3807484757
|
@ -257,7 +257,10 @@ after_initialize do
|
|||
args[:old_trust_level] == TrustLevel[1]
|
||||
|
||||
if SiteSetting.discourse_narrative_bot_enabled && promoted_from_tl1
|
||||
Jobs.enqueue(:send_advanced_tutorial_message, user_id: args[:user_id])
|
||||
# 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])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
1
plugins/discourse-narrative-bot/public/public
Symbolic link
1
plugins/discourse-narrative-bot/public/public
Symbolic link
|
@ -0,0 +1 @@
|
|||
/home/regis/Poetry/discourse/plugins/discourse-narrative-bot/public
|
Loading…
Reference in New Issue
Block a user