Skip to content

Commit

Permalink
Respect context deadline during batch backfill (#438)
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanslade authored Oct 28, 2024
1 parent 88cc975 commit ddd44bb
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions pkg/migrations/backfill.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"time"

"github.com/lib/pq"

"github.com/xataio/pgroll/pkg/db"
"github.com/xataio/pgroll/pkg/schema"
)
Expand All @@ -33,7 +34,6 @@ func Backfill(ctx context.Context, conn db.DB, table *schema.Table, batchSize in
identityColumn: identityColumn,
lastValue: nil,
batchSize: batchSize,
batchDelay: batchDelay,
}

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

time.Sleep(b.batchDelay)
select {
case <-ctx.Done():
return ctx.Err()
case <-time.After(batchDelay):
}
}

return nil
Expand Down Expand Up @@ -88,7 +92,6 @@ type batcher struct {
identityColumn *schema.Column
lastValue *string
batchSize int
batchDelay time.Duration
}

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

0 comments on commit ddd44bb

Please sign in to comment.