From a61811bf4777374f5f9ff7583212417704c7c9fe Mon Sep 17 00:00:00 2001 From: Rowan Seymour Date: Wed, 6 Jul 2022 10:30:47 +0100 Subject: [PATCH] Replace ExitOnCompletion config option with Once which makes it run once and exit --- .gitignore | 1 - archives/config.go | 24 ++++++++++++------------ cmd/rp-archiver/main.go | 19 +++++++++---------- 3 files changed, 21 insertions(+), 23 deletions(-) diff --git a/.gitignore b/.gitignore index 223874a..a40925b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,4 @@ # Binaries for programs and plugins -rp-archiver *.exe *.exe~ *.dll diff --git a/archives/config.go b/archives/config.go index f95d1cf..c1f4a1c 100644 --- a/archives/config.go +++ b/archives/config.go @@ -21,12 +21,12 @@ type Config struct { KeepFiles bool `help:"whether we should keep local archive files after upload (default false)"` UploadToS3 bool `help:"whether we should upload archive to S3"` - ArchiveMessages bool `help:"whether we should archive messages"` - ArchiveRuns bool `help:"whether we should archive runs"` - RetentionPeriod int `help:"the number of days to keep before archiving"` - Delete bool `help:"whether to delete messages and runs from the db after archival (default false)"` - ExitOnCompletion bool `help:"whether archiver should exit after completing archiving job (default false)"` - StartTime string `help:"what time archive jobs should run in UTC HH:MM "` + ArchiveMessages bool `help:"whether we should archive messages"` + ArchiveRuns bool `help:"whether we should archive runs"` + RetentionPeriod int `help:"the number of days to keep before archiving"` + Delete bool `help:"whether to delete messages and runs from the db after archival (default false)"` + StartTime string `help:"what time archive jobs should run in UTC HH:MM "` + Once bool `help:"whether archiver should run once and exit (default false)"` LibratoUsername string `help:"the username that will be used to authenticate to Librato"` LibratoToken string `help:"the token that will be used to authenticate to Librato"` @@ -54,12 +54,12 @@ func NewDefaultConfig() *Config { KeepFiles: false, UploadToS3: true, - ArchiveMessages: true, - ArchiveRuns: true, - RetentionPeriod: 90, - Delete: false, - ExitOnCompletion: false, - StartTime: "00:01", + ArchiveMessages: true, + ArchiveRuns: true, + RetentionPeriod: 90, + Delete: false, + StartTime: "00:01", + Once: false, InstanceName: hostname, } diff --git a/cmd/rp-archiver/main.go b/cmd/rp-archiver/main.go index f525e73..585cc38 100644 --- a/cmd/rp-archiver/main.go +++ b/cmd/rp-archiver/main.go @@ -108,18 +108,17 @@ func main() { analytics.Start() - for { - nextArchival := getNextArchivalTime(timeOfDay) - napTime := time.Until(nextArchival) - - logrus.WithField("sleep_time", napTime).WithField("next_archival", nextArchival).Info("sleeping until next archival") - time.Sleep(napTime) - + if config.Once { doArchival(db, config, s3Client) + } else { + for { + nextArchival := getNextArchivalTime(timeOfDay) + napTime := time.Until(nextArchival) - // ok, we did all our work for our orgs, quit if so configured or sleep until the next day - if config.ExitOnCompletion { - break + logrus.WithField("sleep_time", napTime).WithField("next_archival", nextArchival).Info("sleeping until next archival") + time.Sleep(napTime) + + doArchival(db, config, s3Client) } }