Exemple #1
0
// GetWeather get weather
func GetWeather() []map[string]interface{} {
	weatherChans := make(chan map[string]interface{})
	cities := models.Cities()

	// MAIN loop through cities
	for _, city := range cities {
		go func(ID string) {
			sleep := time.Duration(rand.Intn(1e3)) * time.Millisecond
			utils.Info(fmt.Sprintf("sleeping for... %v", sleep))
			time.Sleep(sleep)

			cityID := fmt.Sprintf("%v", ID)
			weatherChans <- GetCityWeather(cityID)
		}(city)
	}
	defer close(weatherChans)

	results := make([]map[string]interface{}, len(cities))
	for i := 0; i < len(cities); i++ {
		x := <-weatherChans
		results[i] = x
	}

	return results
}
// WeatherCrawlerStart weather crawler start getters
// main weather crawler
func WeatherCrawlerStart(delaySec int, counter int) {
	utils.Info(fmt.Sprintf("initializing weather crawler..."))

	Initialize(&counter)

	for t := range time.Tick(time.Duration(delaySec) * time.Second) {
		fmt.Println(t)
		Initialize(&counter)
	}
}
Exemple #3
0
// PrintWeatherResult print weather result
func PrintWeatherResult(weatherResponse models.WeatherResponse) {
	utils.Info(fmt.Sprintf("%v: %v", weatherResponse.Name, weatherResponse.Main.Temp))
}
Exemple #4
0
func reportGoRoutines(reportDelaySec int) {
	for t := range time.Tick(time.Duration(reportDelaySec) * time.Second) {
		_ = t
		utils.Info(fmt.Sprintf("currently have goroutines -->> %v", runtime.NumGoroutine()))
	}
}