Skip to content

Commit

Permalink
cscli bouncers prune: query creation date if they never connected
Browse files Browse the repository at this point in the history
  • Loading branch information
mmetc committed Jun 12, 2024
1 parent 9a64cbe commit f3518c3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion cmd/crowdsec-cli/bouncers.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ func (cli *cliBouncers) prune(duration time.Duration, force bool) error {
}
}

bouncers, err := cli.db.QueryBouncersLastPulltimeLT(time.Now().UTC().Add(-duration))
bouncers, err := cli.db.QueryBouncersInactiveSince(time.Now().UTC().Add(-duration))
if err != nil {
return fmt.Errorf("unable to query bouncers: %w", err)
}
Expand Down
13 changes: 11 additions & 2 deletions pkg/database/bouncers.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,15 @@ func (c *Client) UpdateBouncerTypeAndVersion(bType string, version string, id in
return nil
}

func (c *Client) QueryBouncersLastPulltimeLT(t time.Time) ([]*ent.Bouncer, error) {
return c.Ent.Bouncer.Query().Where(bouncer.LastPullLT(t)).All(c.CTX)
func (c *Client) QueryBouncersInactiveSince(t time.Time) ([]*ent.Bouncer, error) {
return c.Ent.Bouncer.Query().Where(
// poor man's coalesce

Check warning on line 120 in pkg/database/bouncers.go

View check run for this annotation

Codecov / codecov/patch

pkg/database/bouncers.go#L120

Added line #L120 was not covered by tests
bouncer.Or(
bouncer.LastPullLT(t),
bouncer.And(
bouncer.LastPullIsNil(),
bouncer.CreatedAtLT(t),
),
),
).All(c.CTX)
}

0 comments on commit f3518c3

Please sign in to comment.