This commit is contained in:
@@ -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()
|
||||||
|
|||||||
Reference in New Issue
Block a user