-
Notifications
You must be signed in to change notification settings - Fork 0
/
sync.go
51 lines (41 loc) · 846 Bytes
/
sync.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
package sync
import (
"fmt"
"github.com/robfig/cron/v3"
)
func init() {
initConfig()
initSync()
}
var repoSyncIds = make(map[string]cron.EntryID)
func initSync(){
if len(config.Repos) == 0 {
return
}
crdata := cron.New(cron.WithSeconds())
for _, repo := range config.Repos {
id,err := crdata.AddJob(repo.Cron, NewSyncJob(repo))
repoSyncIds[repo.Name] = id
if err !=nil{
panic(err)
return
}
}
crdata.Start()
}
type SyncJob struct{
Repo Repo
}
func NewSyncJob(repo Repo)SyncJob{
return SyncJob{
Repo: repo,
}
}
func (job SyncJob)Run(){
fmt.Printf("进行git仓库[%s]的同步\n", job.Repo.Name)
err := GitService.Sync(job.Repo.Name)
fmt.Printf("进行git仓库[%s]的同步结束\n", job.Repo.Name)
if err!=nil{
fmt.Printf("进行git仓库[%s]的同步发生错误!%v\n", job.Repo.Name, err)
}
}