milergeo added
This commit is contained in:
@@ -11,11 +11,11 @@ import (
|
||||
|
||||
"doormile/constants"
|
||||
"doormile/db"
|
||||
"doormile/internal/milergeo"
|
||||
"doormile/models"
|
||||
"doormile/utils"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/redis/go-redis/v9"
|
||||
)
|
||||
|
||||
// Catalogue and configuration — §5 of the customer contract.
|
||||
@@ -440,16 +440,7 @@ func milersWithin(lat, lng, radiusKM float64) int {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
|
||||
defer cancel()
|
||||
|
||||
locs, err := db.Rdb.GeoSearchLocation(ctx, "milers:locations", &redis.GeoSearchLocationQuery{
|
||||
GeoSearchQuery: redis.GeoSearchQuery{
|
||||
Longitude: lng,
|
||||
Latitude: lat,
|
||||
Radius: radiusKM,
|
||||
RadiusUnit: "km",
|
||||
Sort: "ASC",
|
||||
Count: 50,
|
||||
},
|
||||
}).Result()
|
||||
locs, err := milergeo.Search(ctx, db.Rdb, lat, lng, radiusKM, 50)
|
||||
if err != nil {
|
||||
utils.Warn("milersWithin: geo search failed", "error", err)
|
||||
return 0
|
||||
|
||||
@@ -17,6 +17,7 @@ import (
|
||||
"doormile/internal/assignment"
|
||||
"doormile/internal/cxstage"
|
||||
"doormile/internal/legs"
|
||||
"doormile/internal/milergeo"
|
||||
"doormile/internal/notify"
|
||||
"doormile/internal/routing"
|
||||
"doormile/models"
|
||||
@@ -371,11 +372,11 @@ func indexMilerLocation(milerUserID int, lat, lon float64) {
|
||||
val := fmt.Sprintf("%f,%f", lat, lon)
|
||||
db.Rdb.Set(ctx, redisKey, val, 30*time.Minute)
|
||||
|
||||
db.Rdb.GeoAdd(ctx, "milers:locations", &redis.GeoLocation{
|
||||
Name: strconv.Itoa(milerUserID),
|
||||
Latitude: lat,
|
||||
Longitude: lon,
|
||||
})
|
||||
// A failed write is a rider auto-assignment can never find; say so
|
||||
// instead of dropping the error.
|
||||
if err := milergeo.Index(ctx, db.Rdb, milerUserID, lat, lon); err != nil {
|
||||
utils.Warn("rider position not indexed for assignment", "miler_id", milerUserID, "error", err)
|
||||
}
|
||||
}
|
||||
|
||||
func UpdateMilerLocation(c *fiber.Ctx) error {
|
||||
|
||||
Reference in New Issue
Block a user