-
Notifications
You must be signed in to change notification settings - Fork 1
/
run.go
65 lines (62 loc) · 1.55 KB
/
run.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package OrgRecord
import (
BaseConfig "github.com/fotomxq/weeekj_core/v5/base/config"
CoreFilter "github.com/fotomxq/weeekj_core/v5/core/filter"
CoreLog "github.com/fotomxq/weeekj_core/v5/core/log"
CoreSQLHistory "github.com/fotomxq/weeekj_core/v5/core/sql/history"
CoreSystemClose "github.com/fotomxq/weeekj_core/v5/core/system_close"
"github.com/robfig/cron/v3"
"time"
)
func Run() {
//捕捉异常
defer func() {
if r := recover(); r != nil {
CoreLog.Error("org record run, ", r)
}
}()
time.Sleep(time.Second * 120)
//启动时间
runTimer = cron.New()
if _, err := runTimer.AddFunc("30 4 * * *", func() {
if runHistoryLock {
return
}
runHistoryLock = true
runHistory()
runHistoryLock = false
}); err != nil {
CoreLog.Error("org record run, cron time, ", err)
}
runTimer.Start()
//卡住进程
CoreSystemClose.Wait()
//退出时间
runTimer.Stop()
}
func runHistory() {
//捕捉异常
defer func() {
if r := recover(); r != nil {
CoreLog.Error("org record run, ", r)
}
}()
//获取归档时间
historyConfig, err := BaseConfig.GetDataString("UserRecordHistoryTime")
if err != nil {
historyConfig = "-168h"
}
historyTime, err := CoreFilter.GetTimeByAdd(historyConfig)
if err != nil {
historyTime = CoreFilter.GetNowTimeCarbon().SubDays(7).Time
}
//处理转移数据
if err = CoreSQLHistory.Run(&CoreSQLHistory.ArgsRun{
BeforeTime: historyTime,
TimeFieldName: "create_at",
OldTableName: "org_record",
NewTableName: "org_record_history",
}); err != nil {
CoreLog.Error("org record run, ", err)
}
}