Add context timeouts for third-party requests
Some checks failed
/ golint (push) Failing after 3m56s

Avoid hanging a goroutine for a long time.
This commit is contained in:
Eli Ribble 2026-05-19 00:24:16 +00:00
parent 2093ea74c4
commit 15d8966971
No known key found for this signature in database
11 changed files with 80 additions and 5 deletions

View file

@ -80,6 +80,9 @@ func restyMiddleware(rclient *resty.Client, response *resty.Response) error {
}
func GeocodeRaw(ctx context.Context, org *models.Organization, address string) (*GeocodeResult, error) {
ctx, cancel := context.WithTimeout(ctx, 15*time.Second)
defer cancel()
req := stadia.RequestGeocodeRaw{
Text: address,
}
@ -95,6 +98,9 @@ func GeocodeRaw(ctx context.Context, org *models.Organization, address string) (
return toGeocodeResult(resp.Features, address, addresses)
}
func GeocodeStructured(ctx context.Context, org *models.Organization, a types.Address) (*GeocodeResult, error) {
ctx, cancel := context.WithTimeout(ctx, 15*time.Second)
defer cancel()
street := fmt.Sprintf("%s %s", a.Number, a.Street)
req := stadia.RequestGeocodeStructured{
Address: &street,
@ -133,6 +139,9 @@ func GetParcel(ctx context.Context, txn bob.Executor, a types.Address) (*models.
return result, nil
}
func ReverseGeocode(ctx context.Context, location types.Location) (*GeocodeResult, error) {
ctx, cancel := context.WithTimeout(ctx, 15*time.Second)
defer cancel()
req := stadia.RequestReverseGeocode{
Latitude: location.Latitude,
Longitude: location.Longitude,
@ -149,6 +158,9 @@ func ReverseGeocode(ctx context.Context, location types.Location) (*GeocodeResul
}
func ReverseGeocodeClosest(ctx context.Context, location types.Location) (*GeocodeResult, error) {
ctx, cancel := context.WithTimeout(ctx, 15*time.Second)
defer cancel()
req := stadia.RequestReverseGeocode{
Latitude: location.Latitude,
Longitude: location.Longitude,