go delete success from more than 12h ago
cicd / ci (push) Successful in 3m39s

This commit is contained in:
bel
2026-06-28 09:23:11 -06:00
parent 43887bb447
commit 831fed82f7
+22
View File
@@ -42,6 +42,7 @@ func run(ctx context.Context) error {
defer wg.Wait() defer wg.Wait()
for _, foo := range []func(context.Context) error{ for _, foo := range []func(context.Context) error{
s.pingAndRecord, s.pingAndRecord,
s.collectGarbage,
s.listen, s.listen,
} { } {
foo := foo foo := foo
@@ -141,6 +142,27 @@ func (s S) listen(ctx context.Context) error {
return nil return nil
} }
func (s S) collectGarbage(ctx context.Context) error {
c := time.NewTicker(time.Hour)
defer c.Stop()
for range c.C {
if _, err := s.ExecContext(ctx, `
DELETE FROM "pinger_pings"
WHERE
start < $1
AND (
ms < 100
OR ok
)
`, time.Now().Add(-1*12*time.Hour).Unix()); err != nil {
log.Println("!", err)
}
}
return nil
}
func (s S) pingAndRecord(ctx context.Context) error { func (s S) pingAndRecord(ctx context.Context) error {
ctx, can := context.WithCancel(ctx) ctx, can := context.WithCancel(ctx)
defer can() defer can()