1
0
mirror of https://github.com/go-micro/go-micro.git synced 2025-01-05 10:20:53 +02:00
go-micro/util/sync/options.go

45 lines
1019 B
Go
Raw Normal View History

2020-04-11 10:33:10 +02:00
package sync
import (
"time"
2021-10-12 13:55:53 +02:00
"go-micro.dev/v4/store"
)
2022-09-30 16:27:07 +02:00
// Options represents Sync options.
type Options struct {
2020-04-11 10:33:10 +02:00
// Stores represents layers in the sync in ascending order. L0, L1, L2, etc
Stores []store.Store
// SyncInterval is the duration between syncs from L0 to L1
SyncInterval time.Duration
// SyncMultiplier is the multiplication factor between each store.
SyncMultiplier int64
}
2022-09-30 16:27:07 +02:00
// Option sets Sync Options.
type Option func(o *Options)
2022-09-30 16:27:07 +02:00
// Stores sets the layers that make up the sync.
func Stores(stores ...store.Store) Option {
return func(o *Options) {
o.Stores = make([]store.Store, len(stores))
for i, s := range stores {
o.Stores[i] = s
}
}
}
2022-09-30 16:27:07 +02:00
// SyncInterval sets the duration between syncs from L0 to L1.
func SyncInterval(d time.Duration) Option {
return func(o *Options) {
o.SyncInterval = d
}
}
2022-09-30 16:27:07 +02:00
// SyncMultiplier sets the multiplication factor for time to wait each sync layer.
func SyncMultiplier(i int64) Option {
return func(o *Options) {
o.SyncMultiplier = i
}
}