Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to set intervals with cli options #568

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions cmd/litestream/replicate.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ func NewReplicateCommand() *ReplicateCommand {
func (c *ReplicateCommand) ParseFlags(ctx context.Context, args []string) (err error) {
fs := flag.NewFlagSet("litestream-replicate", flag.ContinueOnError)
execFlag := fs.String("exec", "", "execute subcommand")
snapshotIntervalFlag := fs.Duration("snapshot-interval", 0, "interval to create snapshots")
validationIntervalFlag := fs.Duration("validation-interval", 0, "interval to validate snapshots")
syncInterval := fs.Duration("sync-interval", litestream.DefaultSyncInterval, "interval to sync replicas")
configPath, noExpandEnv := registerConfigFlag(fs)
fs.Usage = c.Usage
if err := fs.Parse(args); err != nil {
Expand All @@ -55,13 +58,13 @@ func (c *ReplicateCommand) ParseFlags(ctx context.Context, args []string) (err e
if *configPath != "" {
return fmt.Errorf("cannot specify a replica URL and the -config flag")
}

dbConfig := &DBConfig{Path: fs.Arg(0)}
for _, u := range fs.Args()[1:] {
syncInterval := litestream.DefaultSyncInterval
dbConfig.Replicas = append(dbConfig.Replicas, &ReplicaConfig{
URL: u,
SyncInterval: &syncInterval,
URL: u,
SyncInterval: syncInterval,
SnapshotInterval: snapshotIntervalFlag,
ValidationInterval: validationIntervalFlag,
})
}
c.Config.DBs = []*DBConfig{dbConfig}
Expand Down Expand Up @@ -205,5 +208,14 @@ Arguments:
-no-expand-env
Disables environment variable expansion in configuration file.

`[1:], DefaultConfigPath())
-sync-interval DURATION
Snapshot interval duration (Default: %s).

-snapshot-interval DURATION
New snapshot every interval duration (Disabled by default).

-validation-interval DURATION
Run validator every interval duration (Disabled by default).

`[1:], DefaultConfigPath(), litestream.DefaultSyncInterval)
}