Ready to add cron.
This commit is contained in:
parent
f35852b696
commit
9d35088cce
2
LICENSE
2
LICENSE
@ -1,6 +1,6 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2017 蓝眼
|
||||
Copyright (c) 2017 eyebluecn
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
@ -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) {
|
||||
|
||||
//登录身份有效期以数据库中记录的为准
|
||||
|
||||
|
1
go.mod
1
go.mod
@ -12,5 +12,6 @@ require (
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
||||
github.com/modern-go/reflect2 v1.0.1 // indirect
|
||||
github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d
|
||||
github.com/robfig/cron v0.0.0-20180505203441-b41be1df6967
|
||||
golang.org/x/crypto v0.0.0-20190325154230-a5d413f7728c
|
||||
)
|
||||
|
2
go.sum
2
go.sum
@ -108,6 +108,8 @@ github.com/prometheus/procfs v0.0.0-20180725123919-05ee40e3a273/go.mod h1:c3At6R
|
||||
github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
|
||||
github.com/prometheus/procfs v0.0.0-20190117184657-bf6a532e95b1/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
|
||||
github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4=
|
||||
github.com/robfig/cron v0.0.0-20180505203441-b41be1df6967 h1:x7xEyJDP7Hv3LVgvWhzioQqbC/KtuUhTigKlH/8ehhE=
|
||||
github.com/robfig/cron v0.0.0-20180505203441-b41be1df6967/go.mod h1:JGuDeoQd7Z6yL4zQhZ3OPEVHB7fL6Ka6skscFHfmt2k=
|
||||
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
|
||||
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
|
||||
|
Loading…
Reference in New Issue
Block a user