コード例 #1
0
ファイル: job.go プロジェクト: Avialeta/API
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
ファイル: airports.go プロジェクト: Avialeta/API
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()
	}()
}
コード例 #3
0
ファイル: locations.go プロジェクト: Avialeta/API
func LoadLocations() bool {
	log.Info.Print("LoadLocations --start--")
	defer log.Info.Print("LoadLocations --end--")

	types := []string{"countries", "cities", "airports"}
	for _, t := range types {
		l, err := client.LLen(t)
		if err != nil {
			log.Error.Print(err)
			return false
		}

		if l == 0 {
			return false
		}
	}

	var codes []string
	var err error

	codes, err = client.LRange("countries", 0, -1)
	if err != nil {
		log.Error.Print(err)
	} else {
		countries, err := client.HGetAll("countriesNames")
		if err != nil {
			log.Error.Print(err)
		}

		for _, code := range codes {
			name, ok := countries[code]
			if ok {
				country := &search.Location{
					Code: code,
					Name: name,
				}
				search.AddCountry(country)
			}
		}
	}

	codes, err = client.LRange("cities", 0, -1)
	if err != nil {
		log.Error.Print(err)
	} else {
		cities, err := client.HGetAll("citiesNames")
		if err != nil {
			log.Error.Print(err)
		}

		for _, code := range codes {
			name, ok := cities[code]
			if ok {
				city := &search.Location{
					Code: code,
					Name: name,
				}
				search.AddCity(city)
			}
		}
	}

	codes, err = client.LRange("airports", 0, -1)
	if err != nil {
		log.Error.Print(err)
	} else {
		airports, err := client.HGetAll("airportsNames")
		if err != nil {
			log.Error.Print(err)
		}

		for _, code := range codes {
			name, ok := airports[code]
			if ok {
				airport := &search.Location{
					Code: code,
					Name: name,
				}
				search.AddAirport(airport)
			}
		}
	}

	return true
}