-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
reaper.go
32 lines (27 loc) · 850 Bytes
/
reaper.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package services
import (
"time"
"github.com/smartcontractkit/chainlink/core/logger"
"github.com/smartcontractkit/chainlink/core/store"
"github.com/smartcontractkit/chainlink/core/store/orm"
"github.com/smartcontractkit/chainlink/core/utils"
)
type storeReaper struct {
store *store.Store
config orm.ConfigReader
}
// NewStoreReaper creates a reaper that cleans stale objects from the store.
func NewStoreReaper(store *store.Store) utils.SleeperTask {
return utils.NewSleeperTask(&storeReaper{
store: store,
config: store.Config,
})
}
func (sr *storeReaper) Work() {
recordCreationStaleThreshold := sr.config.ReaperExpiration().Before(
sr.config.SessionTimeout().Before(time.Now()))
err := sr.store.DeleteStaleSessions(recordCreationStaleThreshold)
if err != nil {
logger.Error("unable to reap stale sessions: ", err)
}
}