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
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
/home/regis/Poetry/discourse/plugins/discourse-narrative-bot/public
|
Loading…
Reference in New Issue