-
Notifications
You must be signed in to change notification settings - Fork 13
/
remove_expired_geocodings.go
65 lines (44 loc) · 1.49 KB
/
remove_expired_geocodings.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package scripts
import (
"context"
"time"
"github.com/latolukasz/beeorm"
"github.com/coretrix/hitrix/pkg/entity"
"github.com/coretrix/hitrix/service"
"github.com/coretrix/hitrix/service/component/app"
)
type RemoveExpiredGeocodingsScript struct {
}
func (script *RemoveExpiredGeocodingsScript) Run(_ context.Context, _ app.IExit) {
now := service.DI().Clock().Now()
fiveAM := time.Date(now.Year(), now.Month(), now.Day(), 5, 0, 0, 0, now.Location())
if now.After(fiveAM) {
return
}
ormService := service.DI().OrmEngine().Clone()
where := beeorm.NewWhere("ExpiresAt < ?", now)
geocodingEntities := make([]*entity.GeocodingEntity, 0)
ormService.Search(where, beeorm.NewPager(1, 10000), &geocodingEntities)
flusher := ormService.NewFlusher()
for _, geocodingEntity := range geocodingEntities {
flusher.Delete(geocodingEntity)
}
flusher.Flush()
where = beeorm.NewWhere("ExpiresAt < ?", now)
reverseGeocodingEntities := make([]*entity.ReverseGeocodingEntity, 0)
ormService.Search(where, beeorm.NewPager(1, 10000), &reverseGeocodingEntities)
flusher = ormService.NewFlusher()
for _, reverseGeocodingEntity := range reverseGeocodingEntities {
flusher.Delete(reverseGeocodingEntity)
}
flusher.Flush()
}
func (script *RemoveExpiredGeocodingsScript) Interval() time.Duration {
return time.Hour * 3
}
func (script *RemoveExpiredGeocodingsScript) Unique() bool {
return true
}
func (script *RemoveExpiredGeocodingsScript) Description() string {
return "remove expired geocodings"
}