本文整理汇总了Golang中github.com/astaxie/beego/toolbox.StartTask函数的典型用法代码示例。如果您正苦于以下问题:Golang StartTask函数的具体用法?Golang StartTask怎么用?Golang StartTask使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了StartTask函数的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: InitModels
func InitModels() {
setGithubCredentials(beego.AppConfig.String("github::client_id"),
beego.AppConfig.String("github::client_secret"))
docLock = new(sync.RWMutex)
blogLock = new(sync.RWMutex)
parseDocs()
initMaps()
initProuctCase()
updateTask := toolbox.NewTask("check file update", "0 */5 * * * *", checkFileUpdates)
if needCheckUpdate() {
if err := updateTask.Run(); err != nil {
beego.Error(err)
}
beego.AppConfig.Set("app::update_check_time", strconv.Itoa(int(time.Now().Unix())))
}
// ATTENTION: you'd better comment following code when developing.
toolbox.AddTask("check file update", updateTask)
toolbox.StartTask()
}
示例2: a
func a() {
tk := toolbox.NewTask("taska", "0/10 * * * * *", func() error { fmt.Println("hello world"); return nil })
err := tk.Run()
if err != nil {
beego.Error(err)
}
toolbox.AddTask("taska", tk)
toolbox.StartTask()
}
示例3: InitCron
func InitCron() {
if beego.AppConfig.String("runmode") == "prod" {
tk := toolbox.NewTask("statistic", "0 0 * * * *", githubStat)
err := tk.Run()
if err != nil {
log.Warnln("[Run Task Failed]")
log.Warnln(err)
}
toolbox.AddTask("statistic", tk)
toolbox.StartTask()
defer toolbox.StopTask()
}
}
示例4: InitCron
func InitCron() {
tk := toolbox.NewTask("judger", "0/30 * * * * *", task.CheckJudger)
if beego.AppConfig.String("runmode") == "dev" {
err := tk.Run()
if err != nil {
log.Warnln("[Run Task Failed]")
log.Warnln(err)
}
}
toolbox.AddTask("judger", tk)
toolbox.StartTask()
}
示例5: TaskSessionGC
func TaskSessionGC() {
tk := toolbox.NewTask("taska", "* * */1 * * *", func() error {
fmt.Println("hello world")
models.GlobalSessions.GC()
return nil
},
)
err := tk.Run()
if err != nil {
beego.Error(err)
}
toolbox.AddTask("taska", tk)
toolbox.StartTask()
}
示例6: init
func init() {
updateTask := toolbox.NewTask("check file update", "0 */5 * * * *", checkFileUpdates)
if needCheckUpdate() {
if err := updateTask.Run(); err != nil {
beego.Error(err)
}
beego.AppConfig.Set("app::update_check_time", strconv.Itoa(int(time.Now().Unix())))
}
// ATTENTION: you'd better comment following code when developing.
toolbox.AddTask("check file update", updateTask)
toolbox.StartTask()
}
示例7: Run
func (admin *AdminApp) Run() {
if len(toolbox.AdminTaskList) > 0 {
toolbox.StartTask()
}
addr := AdminHttpAddr
if AdminHttpPort != 0 {
addr = fmt.Sprintf("%s:%d", AdminHttpAddr, AdminHttpPort)
}
for p, f := range admin.routers {
http.Handle(p, f)
}
err := http.ListenAndServe(addr, nil)
if err != nil {
BeeLogger.Critical("Admin ListenAndServe: ", err)
}
}
示例8: initCron
func initCron() {
tk1 := toolbox.NewTask("deleteOldPaste", "0 0 * * * *", func() error {
o := orm.NewOrm()
var r orm.RawSeter
r = o.Raw("DELETE FROM paste WHERE Timestamp != 0 AND Timestamp < " + strconv.Itoa(int(time.Now().Unix())))
res, err := r.Exec()
fmt.Println("Deleting old pasts")
if err == nil {
num, _ := res.RowsAffected()
fmt.Println("Affected Rows", num)
} else {
fmt.Println("Database Error: ", err)
}
return nil
})
toolbox.AddTask("deleteOldPaste", tk1)
toolbox.StartTask()
}
示例9: InitModels
func InitModels() {
if !com.IsFile(_CFG_PATH) {
fmt.Println("app.ini文件不存在,创建..")
os.Create(_CFG_PATH)
}
var err error
Cfg, err = goconfig.LoadConfigFile(_CFG_PATH)
if err == nil {
beego.Info("Initialize app.conf")
} else {
fmt.Println(err)
os.Exit(2)
}
// 添加一个定时任务
task0 := toolbox.NewTask("first task", "0 */2 * * * *", firstTask)
toolbox.AddTask("first task", task0)
toolbox.StartTask()
task1 := toolbox.NewTask("first task", "0 */1 * * * *", sendTask)
toolbox.AddTask("send task", task1)
}
示例10: Run
// Run adminApp http server.
// Its addr is defined in configuration file as adminhttpaddr and adminhttpport.
func (admin *adminApp) Run() {
if len(toolbox.AdminTaskList) > 0 {
toolbox.StartTask()
}
addr := AdminHttpAddr
if AdminHttpPort != 0 {
addr = fmt.Sprintf("%s:%d", AdminHttpAddr, AdminHttpPort)
}
for p, f := range admin.routers {
http.Handle(p, f)
}
BeeLogger.Info("Admin server Running on %s", addr)
var err error
if Graceful {
err = grace.ListenAndServe(addr, nil)
} else {
err = http.ListenAndServe(addr, nil)
}
if err != nil {
BeeLogger.Critical("Admin ListenAndServe: ", err, fmt.Sprintf("%d", os.Getpid()))
}
}
示例11: main
func main() {
task := toolbox.NewTask("stock_stat", "0 30 7 * * *", StockTaskNew)
toolbox.AddTask("stock_stat", task)
toolbox.StartTask()
}