zhangqian
2023-08-29 6843bdb44b8d5294a21f2ee30886e0c5ad07a150
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
package initialize
 
import (
    "fmt"
 
    "github.com/robfig/cron/v3"
 
    "srm/config"
    "srm/global"
    "srm/utils"
)
 
func Timer() {
    if global.GVA_CONFIG.Timer.Start {
        for i := range global.GVA_CONFIG.Timer.Detail {
            go func(detail config.Detail) {
                var option []cron.Option
                if global.GVA_CONFIG.Timer.WithSeconds {
                    option = append(option, cron.WithSeconds())
                }
                _, err := global.GVA_Timer.AddTaskByFunc("ClearDB", global.GVA_CONFIG.Timer.Spec, func() {
                    err := utils.ClearTable(global.GVA_DB, detail.TableName, detail.CompareField, detail.Interval)
                    if err != nil {
                        fmt.Println("timer error:", err)
                    }
                }, option...)
                if err != nil {
                    fmt.Println("add timer error:", err)
                }
            }(global.GVA_CONFIG.Timer.Detail[i])
        }
    }
}