Add MOTIS server
This commit is contained in:
@@ -52,8 +52,8 @@ func NewCarpoolRoutingHandler(cfg *viper.Viper) (*CarpoolRoutingHandler, error)
|
||||
}
|
||||
|
||||
// TODO add options (WithTimeDelta, etc...)
|
||||
func (h CarpoolRoutingHandler) Search(results chan *geojson.FeatureCollection, wg *sync.WaitGroup, departure geojson.Feature, destination geojson.Feature, departureDate time.Time) error {
|
||||
defer wg.Done()
|
||||
func (h CarpoolRoutingHandler) Search(results chan *geojson.FeatureCollection, departure geojson.Feature, destination geojson.Feature, departureDate time.Time) error {
|
||||
defer close(results)
|
||||
|
||||
defaultTimeDelta := 3600 * time.Second
|
||||
defaultDepartureRadius := int64(10)
|
||||
@@ -70,6 +70,7 @@ func (h CarpoolRoutingHandler) Search(results chan *geojson.FeatureCollection, w
|
||||
r, err := api.GetDriverJourneys(departure.Point().Lat(), departure.Point().Lon(), destination.Point().Lat(), destination.Point().Lon(), departureDate, &defaultTimeDelta, defaultDepartureRadius, defaultDestinationRadius, defaultCount)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Str("operator", api.GetOperatorId()).Msg("error in carpool api request")
|
||||
return
|
||||
}
|
||||
for _, journey := range r {
|
||||
// Departure
|
||||
|
||||
@@ -6,7 +6,6 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/paulmach/orb/geojson"
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
@@ -31,17 +30,16 @@ func (h *MultimodalRoutingHandler) Search(departure geojson.Feature, destination
|
||||
var wg sync.WaitGroup
|
||||
|
||||
// Carpool
|
||||
wg.Add(1)
|
||||
go h.Carpool.Search(ch, &wg, departure, destination, departureDate)
|
||||
go h.Carpool.Search(ch, departure, destination, departureDate)
|
||||
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
wg.Wait()
|
||||
close(ch)
|
||||
defer wg.Done()
|
||||
for journey := range ch {
|
||||
journeys = append(journeys, journey)
|
||||
}
|
||||
}()
|
||||
|
||||
for journey := range ch {
|
||||
log.Debug().Any("journey", journey).Msg("Received from channel")
|
||||
journeys = append(journeys, journey)
|
||||
}
|
||||
wg.Wait()
|
||||
return journeys, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user