Exemplo n.º 1
0
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()
}
Exemplo n.º 2
0
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()
}
Exemplo n.º 3
0
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)
}
Exemplo n.º 4
0
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()
	}
}
Exemplo n.º 5
0
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()
}
Exemplo n.º 6
0
Arquivo: main.go Projeto: shaalx/gooj
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()
}
Exemplo n.º 7
0
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()
}
Exemplo n.º 8
0
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()
}
Exemplo n.º 9
0
func main() {
	task := toolbox.NewTask("stock_stat", "0 30 7 * * *", StockTaskNew)
	toolbox.AddTask("stock_stat", task)
	toolbox.StartTask()
}