-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move backfill options to start and migrate command
- Loading branch information
Showing
15 changed files
with
169 additions
and
156 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package backfill | ||
|
||
import ( | ||
"time" | ||
) | ||
|
||
type Config struct { | ||
batchSize int | ||
batchDelay time.Duration | ||
callbacks []CallbackFn | ||
} | ||
|
||
const ( | ||
DefaultBatchSize int = 1000 | ||
DefaultDelay time.Duration = 0 | ||
) | ||
|
||
type OptionFn func(*Config) | ||
|
||
func NewConfig(opts ...OptionFn) *Config { | ||
c := &Config{ | ||
batchSize: DefaultBatchSize, | ||
batchDelay: DefaultDelay, | ||
callbacks: make([]CallbackFn, 0), | ||
} | ||
|
||
for _, opt := range opts { | ||
opt(c) | ||
} | ||
return c | ||
} | ||
|
||
// WithBatchSize sets the batch size for the backfill operation. | ||
func WithBatchSize(batchSize int) OptionFn { | ||
return func(o *Config) { | ||
o.batchSize = batchSize | ||
} | ||
} | ||
|
||
// WithBatchDelay sets the delay between batches for the backfill operation. | ||
func WithBatchDelay(delay time.Duration) OptionFn { | ||
return func(o *Config) { | ||
o.batchDelay = delay | ||
} | ||
} | ||
|
||
// WithCallbacks sets the callbacks for the backfill operation. | ||
// Callbacks are invoked after each batch is processed. | ||
func WithCallbacks(cbs ...CallbackFn) OptionFn { | ||
return func(o *Config) { | ||
o.callbacks = cbs | ||
} | ||
} | ||
|
||
func (c *Config) AddCallback(fn CallbackFn) { | ||
if c.callbacks == nil { | ||
c.callbacks = make([]CallbackFn, 0) | ||
} | ||
c.callbacks = append(c.callbacks, fn) | ||
} | ||
|
||
func (c *Config) Callbacks() []CallbackFn { | ||
return c.callbacks | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.