Beispiel #1
0
//cron runs cron, and update everything if it is after specified cycle.
func cron() {
	const (
		shortCycle = 10 * time.Minute
		longCycle  = time.Hour
	)

	go func() {
		getall := true
		for {
			log.Println("short cycle cron started")
			myself.ResetPort()
			ns := node.MustNew(cfg.InitNode.GetData())
			if len(ns) == 0 {
				log.Fatal("no init nodes")
			}
			for _, i := range ns {
				if _, err := i.Ping(); err == nil {
					manager.AppendToList(i)
				}
			}
			nodes := ns[0].GetherNodes()
			doSync(getall)

			manager.Initialize(nodes)
			doSync(getall)
			keylib.Load()
			log.Println("short cycle cron finished")
			getall = false
			<-time.After(shortCycle)
		}
	}()
	go func() {
		for {
			<-time.After(longCycle)
			log.Println("long cycle cron started")
			recentlist.Getall(true)
			thread.CleanRecords()
			thread.RemoveRemoved()
			log.Println("long cycle cron finished")
		}
	}()

}
Beispiel #2
0
//doSync checks nodes in the nodelist are alive, reloads cachelist, removes old removed files,
//reloads all tags from cachelist,reload srecent list from nodes in search list,
//and reloads cache info from files in the disk.
func doSync(fullRecent bool) {
	if manager.ListLen() == 0 {
		return
	}
	log.Println("recentList.getall start")
	recentlist.Getall(fullRecent)
	recentlist.RemoveOlds()
	log.Println("recentList.getall finished")

	if cfg.HeavyMoon && !running {
		log.Println("running heavymoon...")
		thread.CreateAllCachedirs()
		running = true
		go func() {
			log.Println("cacheList.getall start")
			download.Getall()
			log.Println("cacheList.getall finished")
			running = false
			log.Println("heavymoon end")
		}()
	}
}