func NewExecutor(jobList *JobList, taskList *TaskList, runList *RunList) *Executor { cron := cronService.New() cron.Start() return &Executor{ cron, jobList, taskList, runList, } }
//执行定时器任务 func SysTask(settings map[string]string) { defer func() { if x := recover(); x != nil { log.Printf("caught panic: %v", x) } }() c := cron.New() //生成排名对象 rankobj := NewRankTask() c.AddFunc("0 0 * * * ?", rankobj.PVRank, "pvrank") c.AddFunc("0 0 * * * ?", rankobj.CollectRank, "collectrank") c.Start() }
/*启动*/ func (sys *SysIni) StartNoSqlSys() { fmt.Println("StartNoSqlSys is start................") //单次同步 c := cron.New() c.Start() defer c.Stop() for j := range sys.singleXmlInfoes { singleXmlInfo := sys.singleXmlInfoes[j] c.AddFunc(sys.configInfo.singletimer, func() { logger.Info("single[", singleXmlInfo.FileName, "] job is run ......................") NoSqlSync(&sys.dbini, &sys.singleXmlInfoes[j]) }, singleXmlInfo.FileName) } for { time.Sleep(2 * time.Second) } }
/*启动*/ func (sys *SysIni) StartSys() { fmt.Println("SysIni is start................") StartFlag = true if StartFlag { //判断标记位并增加标记位 for i := range sys.xmlInfoes { Alter(&sys.dbini, &sys.xmlInfoes[i]) logger.Info("Alter >>>>>>>>>>>>>>>>:", i) } } logger.Info("StartSys >>>>>>>>>>>>>>>>goto for ") //单次同步 c := cron.New() c.Start() defer c.Stop() fmt.Println("singletimer>>>>", sys.configInfo.singletimer) //单次同步 for j := range sys.singleXmlInfoes { go func(sys *SysIni, j int) { singleXmlInfo := sys.singleXmlInfoes[j] c.AddFunc(sys.configInfo.singletimer, func() { logger.Info("single[", singleXmlInfo.FileName, "] job is run ......................") singleXmlInfo.RunSingleDataPipe(&sys.dbini) }, singleXmlInfo.FileName) }(sys, j) } //实时同步 for StartFlag { //边读边写,更新 for i := range sys.xmlInfoes { //logger.Info("sys.xmlInfoes[i].NotExistData >>>>>>>>>>>>>>>>", sys.xmlInfoes[i].Remark, sys.xmlInfoes[i].NotExistData) if sys.xmlInfoes[i].NotExistData { Check(&sys.dbini, &sys.xmlInfoes[i]) } if sys.xmlInfoes[i].CheckFlag { sys.xmlInfoes[i].RunDataPipe(&sys.dbini) } } time.Sleep(2 * time.Second) } }
func NewBot(client *xmpp.Client, cfg config.Config, f NewFunc) *Bot { b := &Bot{ client: client, cron: cron.New(), cfg: cfg, web: NewWebServer(cfg.Setup.WebHost, cfg.Setup.WebPort), createPlugin: f, } // 自动启用内置插件 admin := NewAdmin("admin") b.admin = admin b.plugins = append(b.plugins, admin) for name, v := range cfg.Plugin { if v["enable"].(bool) { //模块是否被启用 plugin := f(name, v) if plugin != nil && plugin.CheckEnv() { //模块运行环境是否满足 b.plugins = append(b.plugins, plugin) } } } return b }
func init() { c = cron.New() }
func init() { c = cron.New() c.Start() // c.AddFunc("0 * * * *", func() { fmt.Println("test ran at " + time.Now().Format("2006-01-02 15:04:05")) }, "test") }