-
Notifications
You must be signed in to change notification settings - Fork 2
/
cron.go
47 lines (42 loc) · 1.35 KB
/
cron.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
package app
import (
"strconv"
"github.com/robfig/cron/v3"
"github.com/sirupsen/logrus"
)
func jobs(logger logrus.FieldLogger, app *App) error {
c := cron.New(cron.WithChain(
cron.Recover(cron.VerbosePrintfLogger(logger)), // or use cron.DefaultLogger
))
_, err := c.AddFunc("@every "+strconv.Itoa(app.Config.Crontab.Tor)+"h", func() { app.TorGenerator.Run(app.Config.Crontab.Tor) })
if err != nil {
return err
}
_, err = c.AddFunc("@every "+strconv.Itoa(app.Config.Crontab.Spam)+"h", func() { app.SpamGenerator.Run(app.Config.Crontab.Spam) })
if err != nil {
return err
}
_, err = c.AddFunc("@every "+strconv.Itoa(app.Config.Crontab.VPN)+"h", func() { app.VPNGenerator.Run(app.Config.Crontab.VPN) })
if err != nil {
return err
}
_, err = c.AddFunc("@every "+strconv.Itoa(app.Config.Crontab.Proxy)+"h", func() { app.ProxyGenerator.Run(app.Config.Proxy.Workers, app.Config.Crontab.Proxy) })
if err != nil {
return err
}
_, err = c.AddFunc("@every "+strconv.Itoa(app.Config.Crontab.Proxy)+"h", func() { app.ProxyGenerator.Run(app.Config.Proxy.Workers, app.Config.Crontab.Proxy) })
if err != nil {
return err
}
_, err = c.AddFunc("@every "+strconv.Itoa(app.Config.Crontab.Maxmind)+"h", func() {
err = app.Maxmind.DownloadAndUpdate()
if err != nil {
app.Logger.Error(err)
}
})
if err != nil {
return err
}
c.Start()
return nil
}