Skip to content

Commit

Permalink
Merge pull request #44 from tybritten/master
Browse files Browse the repository at this point in the history
Add scheduling options
  • Loading branch information
nicpottier authored Aug 24, 2020
2 parents 409f7e9 + 0fed584 commit 09a5b14
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 12 deletions.
15 changes: 11 additions & 4 deletions cmd/rp-archiver/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,12 @@ func main() {
}

for {
start := time.Now().In(time.UTC)
// convert the starttime to time.Time
layout := "15:04"
start, err := time.Parse(layout, config.StartTime)
if err != nil {
logrus.WithError(err).Fatal("invalid start time supplied")
}

// get our active orgs
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
Expand Down Expand Up @@ -115,10 +120,12 @@ func main() {
cancel()
}

// ok, we did all our work for our orgs, sleep until the next day
// ok, we did all our work for our orgs, quit if so configured or sleep until the next day
if config.ExitOnCompletion {
break
}
nextDay := start.AddDate(0, 0, 1)
nextDay = time.Date(nextDay.Year(), nextDay.Month(), nextDay.Day(), 0, 1, 0, 0, time.UTC)
napTime := nextDay.Sub(start)
napTime := nextDay.Sub(time.Now().In(time.UTC))

if napTime > time.Duration(0) {
logrus.WithField("time", napTime).Info("Sleeping until next UTC day")
Expand Down
20 changes: 12 additions & 8 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,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)"`
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 "`
}

// NewConfig returns a new default configuration object
Expand All @@ -44,10 +46,12 @@ func NewConfig() *Config {
KeepFiles: false,
UploadToS3: true,

ArchiveMessages: true,
ArchiveRuns: true,
RetentionPeriod: 90,
Delete: false,
ArchiveMessages: true,
ArchiveRuns: true,
RetentionPeriod: 90,
Delete: false,
ExitOnCompletion: false,
StartTime: "00:01",
}

return &config
Expand Down

0 comments on commit 09a5b14

Please sign in to comment.