Ready to add cron.
This commit is contained in:
@ -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() {
|
||||
|
||||
}
|
||||
|
||||
|
@ -185,7 +185,7 @@ func (this *Context) InstallOk() {
|
||||
this.OpenDb()
|
||||
|
||||
for _, bean := range this.BeanMap {
|
||||
bean.ConfigPost()
|
||||
bean.Bootstrap()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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()
|
||||
}
|
||||
|
||||
//每日清洗离线数据表。
|
||||
|
@ -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)
|
||||
|
@ -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) {
|
||||
|
||||
//登录身份有效期以数据库中记录的为准
|
||||
|
||||
|
Reference in New Issue
Block a user