Пример #1
0
func (rss *SchedulableRSS) DoWork(scheduler *scheduler.Scheduler) {
	fmt.Println("goint to run RSS")
	resp, err := http.Get(rss.RSSFeed.GetLink())
	if err != nil {
		// TODO: error checking here
		fmt.Println("error getting RSS:", err)
		return
	}

	defer resp.Body.Close()
	body, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		fmt.Println("error reading body")
		// TODO: error handling
		return
	}

	err = GetStories(rss.RSSFeed, body)
	if err != nil {
		fmt.Println("error getting stories")
		return
	}

	fmt.Println("OK")
	// TODO: use config file to control the timing here
	toSchedule := CreateSchedulableArticle(rss.RSSFeed.GetChannel().GetArticle(0), 1)
	go scheduler.AddSchedulable(toSchedule)
	if rss.IsLoopable() && scheduler.IsRunning() {
		rss.start = time.Now()
		go scheduler.AddSchedulable(rss)
	}
}
Пример #2
0
func SignalDone(s *scheduler.Scheduler, c chan bool) {
	<-c
	time.Sleep(time.Duration(2) * time.Second)
	s.Stop()
}