sunty
2024-04-30 a1fdc969dd20a97087e986c69fdfd25ffe115368
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
package main
 
import (
    "ruleModelEngine/config"
    //"annotation_service/db"
    "basic.com/valib/logger.git"
    "flag"
    "ruleModelEngine/rule"
    "time"
)
 
var env = flag.String("app", "app", "read database info")
 
func init() {
    config.Init(*env)
    var logFile = config.LogConf.Path + "annotation_service.log"
    logger.InitLogger(logFile, config.LogConf.Level, config.LogConf.MaxSize, config.LogConf.MaxBackups, config.LogConf.MaxAge)
    logger.Info("loginit success !")
 
}
 
func main() {
    //db.UpdatePersonStatusByIds()
    immediate := flag.Bool("immediate", true, "whether to execute immediately")
    flag.Parse()
 
    if *immediate {
        logger.Info("Executing immediately...")
        rule.ExecuteTask()
    }
 
    now := time.Now()
    next := time.Date(now.Year(), now.Month(), now.Day()+1, 1, 0, 0, 0, now.Location())
    duration := next.Sub(now)
 
    timer := time.NewTimer(duration)
    logger.Info("The program has started and will execute at one o'clock in the early morning every night.")
    for {
        <-timer.C
        logger.Info("Executing at 1 AM...")
        rule.ExecuteTask()
        next = next.Add(24 * time.Hour)
        timer.Reset(next.Sub(time.Now()))
    }
 
}