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() }
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() }
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() } }
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() }
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() }
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() }
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) } }
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() }
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) }
// 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())) } }
func main() { task := toolbox.NewTask("stock_stat", "0 30 7 * * *", StockTaskNew) toolbox.AddTask("stock_stat", task) toolbox.StartTask() }