@@ -189,16 +189,29 @@ private void Validate(DependencyQueue<SeedModule> queue)
189189
190190 private async Task SeedWorkerMainAsync ( QueueContext context )
191191 {
192- await using var connection = Connect ( context ) ;
192+ try
193+ {
194+ await using var connection = Connect ( context ) ;
193195
194- await PrepareAsync ( connection , context ) ;
196+ await PrepareAsync ( connection , context ) ;
195197
196- bool CanTake ( SeedModule module )
197- => module . WorkerId == 0
198- || module . WorkerId == context . WorkerId ;
198+ bool CanTake ( SeedModule module )
199+ => module . WorkerId == 0
200+ || module . WorkerId == context . WorkerId ;
199201
200- while ( await context . GetNextEntryAsync ( CanTake ) is { Value : var module } )
201- await ExecuteAsync ( module , connection , context ) ;
202+ while ( await context . GetNextEntryAsync ( CanTake ) is { Value : var module } )
203+ await ExecuteAsync ( module , connection , context ) ;
204+ }
205+ catch ( OperationCanceledException )
206+ {
207+ // Not an error, but need to flow cancellation to caller
208+ throw ;
209+ }
210+ catch ( Exception e )
211+ {
212+ HandleError ( e , context ) ;
213+ throw ;
214+ }
202215 }
203216
204217 private ISeedTargetConnection Connect ( QueueContext context )
@@ -236,6 +249,14 @@ private async Task ExecuteAsync(SeedModule module, ISeedTargetConnection connect
236249 Interlocked . Increment ( ref _appliedCount ) ;
237250 }
238251
252+ private void HandleError ( Exception e , QueueContext context )
253+ {
254+ if ( e . Data is { IsReadOnly : false } data )
255+ data [ nameof ( context . WorkerId ) ] = context . WorkerId ;
256+
257+ context . SetEnding ( ) ;
258+ }
259+
239260 private void ReportStarting ( )
240261 {
241262 _stopwatch . Restart ( ) ;
0 commit comments