Пример #1
0
func Scheduler() {
	log.Info.Print("Run Scheduler")

	if RestoreCountries() {
		RestoreCities()
		RestoreAirports()
		RestoreAirlines()

		for id := range Countries {
			search.AddCountry(mapCountry(Countries[id]))
		}

		for id := range Cities {
			search.AddCity(mapCity(Cities[id]))
		}

		for id := range Airports {
			search.AddAirport(mapAirport(Airports[id]))
		}

		search.CreateCitiesStr()
		search.CreateAirportsStr()

		log.Info.Println("Restore")
		return
	}

	chRawCountries := fetchCountries()

	chCountriesCities, chCountriesAirports := processCountries(chRawCountries)

	rawCities := fetchCities(chCountriesCities)
	rawAirports := fetchAirports(chCountriesAirports)

	processCities(rawCities)
	processAirports(rawAirports)

	go fetchAirlines()
}
Пример #2
0
func processAirports(chRawAirports <-chan ovio.Airport) {
	go func() {
		for rawAirport := range chRawAirports {
			airport := Airport{
				Id:          rawAirport.Id,
				Name:        rawAirport.Name,
				CityCode:    rawAirport.City,
				CountryCode: rawAirport.Country,
			}

			location := fetchLocations(Countries[airport.CountryCode].Name + ", " + Cities[airport.CityCode].Name)
			timeZone := fetchTimeZones(location)
			airport.TimeZone = timeZone

			Airports[airport.Id] = airport

			search.AddAirport(mapAirport(airport))
			cache.SaveAirports(airport.Map())
		}

		search.CreateCitiesStr()
	}()
}