Skip to content

Commit ddd44bb

Browse files
authored
Respect context deadline during batch backfill (#438)
1 parent 88cc975 commit ddd44bb

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

pkg/migrations/backfill.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"time"
1111

1212
"github.com/lib/pq"
13+
1314
"github.com/xataio/pgroll/pkg/db"
1415
"github.com/xataio/pgroll/pkg/schema"
1516
)
@@ -33,7 +34,6 @@ func Backfill(ctx context.Context, conn db.DB, table *schema.Table, batchSize in
3334
identityColumn: identityColumn,
3435
lastValue: nil,
3536
batchSize: batchSize,
36-
batchDelay: batchDelay,
3737
}
3838

3939
// Update each batch of rows, invoking callbacks for each one.
@@ -49,7 +49,11 @@ func Backfill(ctx context.Context, conn db.DB, table *schema.Table, batchSize in
4949
return err
5050
}
5151

52-
time.Sleep(b.batchDelay)
52+
select {
53+
case <-ctx.Done():
54+
return ctx.Err()
55+
case <-time.After(batchDelay):
56+
}
5357
}
5458

5559
return nil
@@ -88,7 +92,6 @@ type batcher struct {
8892
identityColumn *schema.Column
8993
lastValue *string
9094
batchSize int
91-
batchDelay time.Duration
9295
}
9396

9497
func (b *batcher) updateBatch(ctx context.Context, conn db.DB) error {

0 commit comments

Comments
 (0)