1package db
2
3import (
4	sq "github.com/Masterminds/squirrel"
5)
6
7//go:generate counterfeiter . WorkerArtifactLifecycle
8
9type WorkerArtifactLifecycle interface {
10	RemoveExpiredArtifacts() error
11}
12
13type artifactLifecycle struct {
14	conn Conn
15}
16
17func NewArtifactLifecycle(conn Conn) *artifactLifecycle {
18	return &artifactLifecycle{
19		conn: conn,
20	}
21}
22
23func (lifecycle *artifactLifecycle) RemoveExpiredArtifacts() error {
24
25	_, err := psql.Delete("worker_artifacts").
26		Where(sq.Expr("created_at < NOW() - interval '12 hours'")).
27		RunWith(lifecycle.conn).
28		Exec()
29
30	return err
31}
32