From dfbc3562d0f73ec7f47eb6806dc45c0f59a2e0b6 Mon Sep 17 00:00:00 2001 From: Tyler Britten <1933680+tybritten@users.noreply.github.com> Date: Tue, 7 Jan 2020 19:29:42 -0500 Subject: [PATCH] Add configurable archive length --- archiver.go | 4 ++-- cmd/rp-archiver/main.go | 2 +- config.go | 2 ++ 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/archiver.go b/archiver.go index a97549d..b2504e6 100644 --- a/archiver.go +++ b/archiver.go @@ -105,7 +105,7 @@ WHERE o.is_active = TRUE order by o.id ` // GetActiveOrgs returns the active organizations sorted by id -func GetActiveOrgs(ctx context.Context, db *sqlx.DB) ([]Org, error) { +func GetActiveOrgs(ctx context.Context, db *sqlx.DB, conf *Config) ([]Org, error) { ctx, cancel := context.WithTimeout(ctx, time.Minute) defer cancel() @@ -117,7 +117,7 @@ func GetActiveOrgs(ctx context.Context, db *sqlx.DB) ([]Org, error) { orgs := make([]Org, 0, 10) for rows.Next() { - org := Org{ActiveDays: 90} + org := Org{ActiveDays: conf.ArchiveLength} err = rows.StructScan(&org) if err != nil { return nil, errors.Wrapf(err, "error scanning active org") diff --git a/cmd/rp-archiver/main.go b/cmd/rp-archiver/main.go index a6e3693..eebad4e 100644 --- a/cmd/rp-archiver/main.go +++ b/cmd/rp-archiver/main.go @@ -84,7 +84,7 @@ func main() { // get our active orgs ctx, cancel := context.WithTimeout(context.Background(), time.Minute) - orgs, err := archiver.GetActiveOrgs(ctx, db) + orgs, err := archiver.GetActiveOrgs(ctx, db, config) cancel() if err != nil { diff --git a/config.go b/config.go index 061b279..1f98994 100644 --- a/config.go +++ b/config.go @@ -21,6 +21,7 @@ type Config struct { ArchiveMessages bool `help:"whether we should archive messages"` ArchiveRuns bool `help:"whether we should archive runs"` + ArchiveLength int `help:"how many days back to archive"` Delete bool `help:"whether to delete messages and runs from the db after archival (default false)"` } @@ -45,6 +46,7 @@ func NewConfig() *Config { ArchiveMessages: true, ArchiveRuns: true, + ArchiveLength: 90, Delete: false, }