Exemplo n.º 1
0
func (this *Scheduler) Run() {
	go this.httpService()

	//a cronjob wrapper for add tasks
	f := func(dummy ...interface{}) {
		this.AddTasksFromRules()
	}
	cronJob := lib.InitCronJob(f, nil, this.fetchRulesPeriod)
	go cronJob.Run()

	//a cronjob wrapper for DispatchTasks
	f1 := func(dummy ...interface{}) {
		this.DispatchTasks()
	}
	cronJob1 := lib.InitCronJob(f1, nil, this.fetchTasksPeriod)
	go cronJob1.Run()

	go this.redisPool.KeepAlive(this.redisHeartbeat)

	go utils.HandleQuitSignal(func() {
		close(this.quitChan)
	})

	<-this.quitChan
}
Exemplo n.º 2
0
//启动Fetcher
func (this *Fetcher) Run() {
	//启动api server
	go this.httpService()
	for i := 0; i < this.nWorkers; i++ {
		this.wg.Add(1)
		go this.fetchPage(this.pageStore)
	}
	log.Infoln("start ", this.nWorkers, " fetch workers...")

	go utils.HandleQuitSignal(func() {
		close(this.quitChan)
	})

	this.wg.Wait()
}