Exemplo n.º 1
0
func processCities(chRawCities <-chan ovio.City) {
	go func() {
		for rawCity := range chRawCities {
			city := City{
				Id:          rawCity.Code,
				Name:        rawCity.Name,
				CountryCode: rawCity.Country,
			}

			Cities[city.Id] = city

			search.AddCity(mapCity(city))
			cache.SaveCities(city.Map())
		}

		search.CreateAirportsStr()
	}()
}
Exemplo n.º 2
0
Arquivo: job.go Projeto: 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()
}
Exemplo n.º 3
0
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
}