File tree Expand file tree Collapse file tree 1 file changed +15
-4
lines changed Expand file tree Collapse file tree 1 file changed +15
-4
lines changed Original file line number Diff line number Diff line change @@ -52,15 +52,26 @@ public PostgreSqlWriteOnlyTransaction(
52
52
public override void Commit ( )
53
53
{
54
54
_storage . UseTransaction ( _dedicatedConnectionFunc ( ) , ( connection , _ ) => {
55
+ RegisterNewJobsEventWithTransactionCompletedEvent ( ) ;
55
56
foreach ( Action < IDbConnection > command in _commandQueue )
56
57
{
57
58
command ( connection ) ;
58
59
}
59
60
} , CreateTransactionScope ) ;
60
-
61
- // Triggers signals for all queues to which jobs have been added in this transaction
62
- _queuesWithAddedJobs . ForEach ( PostgreSqlJobQueue . _queueEventRegistry . Set ) ;
63
- _queuesWithAddedJobs . Clear ( ) ;
61
+ }
62
+
63
+ private void RegisterNewJobsEventWithTransactionCompletedEvent ( )
64
+ {
65
+ // TransactionCompleted event is required here, because if this TransactionScope is enlisted
66
+ // within an ambient TransactionScope, the ambient TransactionScope controls when the TransactionScope completes.
67
+ Transaction . Current . TransactionCompleted += ( _ , args ) => {
68
+ if ( args . Transaction . TransactionInformation . Status == TransactionStatus . Committed )
69
+ {
70
+ // Triggers signals for all queues to which jobs have been added in this transaction
71
+ _queuesWithAddedJobs . ForEach ( PostgreSqlJobQueue . _queueEventRegistry . Set ) ;
72
+ _queuesWithAddedJobs . Clear ( ) ;
73
+ }
74
+ } ;
64
75
}
65
76
66
77
private TransactionScope CreateTransactionScope ( )
You can’t perform that action at this time.
0 commit comments