Skip to content

Commit

Permalink
store: purge old jobs and logs >30d old
Browse files Browse the repository at this point in the history
Signed-off-by: Stephen Gutekanst <[email protected]>
  • Loading branch information
emidoots committed Oct 4, 2024
1 parent f827edc commit 2654f8b
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions internal/wrench/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,25 @@ type JobsFilter struct {
Limit int
}

var lastPurge time.Time

func (s *Store) purgeOldData(ctx context.Context) error {
if !lastPurge.IsZero() && time.Since(lastPurge) < 24*time.Hour {
return nil
}
lastPurge = time.Now()
_, err := s.db.ExecContext(ctx, `
DELETE FROM runner_jobs WHERE created_at < datetime('now', '-30 days');
DELETE FROM logs WHERE timestamp < datetime('now', '-30 days');
`)
return err
}

func (s *Store) Jobs(ctx context.Context, filters ...JobsFilter) ([]api.Job, error) {
if err := s.purgeOldData(ctx); err != nil {
return nil, errors.Wrap(err, "purgeOldData")
}

var conds []*sqlf.Query
limit := sqlf.Sprintf("")
for _, where := range filters {
Expand Down

0 comments on commit 2654f8b

Please sign in to comment.