-
Notifications
You must be signed in to change notification settings - Fork 0
/
scheduler.go
41 lines (32 loc) · 945 Bytes
/
scheduler.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
package scheduler
import (
"context"
"fmt"
"github.com/adedayo/checkmate-core/pkg/projects"
"github.com/adedayo/checkmate/pkg/api"
"github.com/robfig/cron/v3"
)
func schedule(spec string, f func()) {
c := cron.New()
c.AddFunc(spec, f)
c.Start()
}
func ScheduleReposiroryTracking(config Config) {
pm := config.ProjectManager
spec := fmt.Sprintf("@every %ds", config.Frequency)
schedule(spec, func() {
updateCommitDBs(context.Background(), pm, callback, config)
})
select {}
}
func callback(projID string, data interface{}) {
for _, ws := range api.GetListeningSocketsByProjectID(projID) {
ws.WriteJSON(data)
}
}
type Config struct {
Frequency int //how often, in seconds the schedule should be run
DataDir string //CheckMate data directory
ScanOlderCommits bool //whether commits, prior to HEAD, should be scanned. TODO: set this from the parameters
ProjectManager projects.ProjectManager
}