Ready to add cron.

This commit is contained in:
zicla
2019-04-26 21:36:00 +08:00
parent f35852b696
commit 9d35088cce
8 changed files with 33 additions and 7 deletions

View File

@ -14,7 +14,7 @@ type IBean interface {
//系统清理方法
Cleanup()
//所有配置都加载完成后调用的方法,包括数据库加载完毕
ConfigPost()
Bootstrap()
//快速的Panic方法
PanicError(err error)
}
@ -27,7 +27,7 @@ func (this *Bean) Init() {
this.logger = logger.LOGGER
}
func (this *Bean) ConfigPost() {
func (this *Bean) Bootstrap() {
}

View File

@ -185,7 +185,7 @@ func (this *Context) InstallOk() {
this.OpenDb()
for _, bean := range this.BeanMap {
bean.ConfigPost()
bean.Bootstrap()
}
}

View File

@ -2,6 +2,7 @@ package rest
import (
"github.com/eyebluecn/tank/code/tool/util"
"github.com/robfig/cron"
"time"
)
@ -50,10 +51,32 @@ func (this *DashboardService) Init() {
}
//系统启动,数据库配置完毕后会调用该方法
func (this *DashboardService) ConfigPost() {
func (this *DashboardService) Bootstrap() {
//立即执行数据清洗任务
go util.SafeMethod(this.maintain)
//每天00:05执行数据清洗任务
i := 0
c := cron.New()
//AddFunc
spec := "*/5 * * * * ?"
err := c.AddFunc(spec, func() {
i++
this.logger.Info("cron running: %d", i)
})
this.PanicError(err)
//AddJob方法
//c.AddJob(spec, TestJob{})
//c.AddJob(spec, Test2Job{})
//启动计划任务
c.Start()
//关闭着计划任务, 但是不能关闭已经在执行中的任务.
defer c.Stop()
}
//每日清洗离线数据表。

View File

@ -135,7 +135,7 @@ func (this *Router) ServeHTTP(writer http.ResponseWriter, request *http.Request)
//已安装的模式
//统一处理用户的身份信息。
this.userService.bootstrap(writer, request)
this.userService.preHandle(writer, request)
if handler, ok := this.routeMap[path]; ok {
handler(writer, request)

View File

@ -71,7 +71,7 @@ func (this *UserService) MatterUnlock(userUuid string) {
//装载session信息如果session没有了根据cookie去装填用户信息。
//在所有的路由最初会调用这个方法
func (this *UserService) bootstrap(writer http.ResponseWriter, request *http.Request) {
func (this *UserService) preHandle(writer http.ResponseWriter, request *http.Request) {
//登录身份有效期以数据库中记录的为准