This commit is contained in:
@@ -42,6 +42,7 @@ func run(ctx context.Context) error {
|
||||
defer wg.Wait()
|
||||
for _, foo := range []func(context.Context) error{
|
||||
s.pingAndRecord,
|
||||
s.collectGarbage,
|
||||
s.listen,
|
||||
} {
|
||||
foo := foo
|
||||
@@ -141,6 +142,27 @@ func (s S) listen(ctx context.Context) error {
|
||||
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 {
|
||||
ctx, can := context.WithCancel(ctx)
|
||||
defer can()
|
||||
|
||||
Reference in New Issue
Block a user