-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathcron.go
More file actions
45 lines (41 loc) · 1.16 KB
/
cron.go
File metadata and controls
45 lines (41 loc) · 1.16 KB
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
package main
import (
"github.com/datatogether/core"
"time"
)
// StartCron spins up a ticker that will run cron jobs (currently just calculating base Primer Stats)
// at a given interval
// TODO - this should move to a que to clear the way for running lots & lots
// of copies of sentry
func StartCron(d time.Duration) (stop func()) {
t := time.NewTicker(d)
go func() {
for {
select {
case <-t.C:
if err := CalcBasePrimerStats(); err != nil {
log.Debug(err)
}
}
}
}()
return t.Stop
}
// CalcBasePrimerStats calculates the tallies for primers that have no parent
// Primer by calculating stats for all of their child primers & working up the chain
// This process is very computationally expensive, and should be run selectively
// TODO - this currently spins up at least 1Gig of ram to do it's work, need to refactor
func CalcBasePrimerStats() error {
log.Info("[INFO] starting base primer stat calculation")
ps, err := core.BasePrimers(appDB, 100, 0)
if err != nil {
return err
}
for _, p := range ps {
if err := p.CalcStats(appDB); err != nil {
return err
}
}
log.Info("[INFO] base primer stat calculation finished.")
return nil
}