diff --git a/background/arcgis.go b/background/arcgis.go index 7fd1c40b..da3c53ac 100644 --- a/background/arcgis.go +++ b/background/arcgis.go @@ -397,17 +397,17 @@ func NewFieldSeeker(ctx context.Context, oauth *models.OauthToken) (*fieldseeker RefreshTokenExpires: oauth.RefreshTokenExpires, }, ) - if err != nil { - return nil, fmt.Errorf("Failed to create ArcGIS client: %w", err) - } - log.Info().Str("context", context).Str("host", host).Msg("Using base fieldseeker URL") - fssync, err := fieldseeker.NewFieldSeekerFromURL(ctx, *ar, row.FieldseekerURL.MustGet()) if err != nil { if errors.Is(err, arcgis.ErrorInvalidAuthToken) { return nil, InvalidatedTokenError{} } else if errors.Is(err, arcgis.ErrorInvalidRefreshToken) { return nil, InvalidatedTokenError{} } + return nil, fmt.Errorf("Failed to create ArcGIS client: %w", err) + } + log.Info().Str("context", context).Str("host", host).Msg("Using base fieldseeker URL") + fssync, err := fieldseeker.NewFieldSeekerFromURL(ctx, *ar, row.FieldseekerURL.MustGet()) + if err != nil { return nil, fmt.Errorf("Failed to create Fieldseeker client: %w", err) } return fssync, nil @@ -522,6 +522,10 @@ func periodicallyExportFieldseeker(ctx context.Context, org *models.Organization oauth, ) if err != nil { + if errors.Is(err, &InvalidatedTokenError{}) { + log.Info().Int32("org", org.ID).Msg("oauth token for org is invalid, waiting for refresh") + continue + } return fmt.Errorf("Failed to create fieldseeker client: %w", err) } logPermissions(ctx, fssync) @@ -620,14 +624,14 @@ func maintainOAuth(ctx context.Context, oauth *models.OauthToken) error { return fmt.Errorf("Failed to update oauth token from database: %w", err) } var accessTokenDelay time.Duration - if oauth.AccessTokenExpires.Before(time.Now()) { - accessTokenDelay = 1 + if oauth.AccessTokenExpires.Before(time.Now()) || time.Until(oauth.AccessTokenExpires) < (3*time.Second) { + accessTokenDelay = time.Second } else { accessTokenDelay = time.Until(oauth.AccessTokenExpires) - (3 * time.Second) } var refreshTokenDelay time.Duration - if oauth.RefreshTokenExpires.Before(time.Now()) { - refreshTokenDelay = 1 + if oauth.RefreshTokenExpires.Before(time.Now()) || time.Until(oauth.RefreshTokenExpires) < (3*time.Second) { + refreshTokenDelay = time.Second } else { refreshTokenDelay = time.Until(oauth.RefreshTokenExpires) - (3 * time.Second) } diff --git a/html/template/sync/pool-by-id.html b/html/template/sync/pool-by-id.html index 856dcfa6..9d937b27 100644 --- a/html/template/sync/pool-by-id.html +++ b/html/template/sync/pool-by-id.html @@ -48,7 +48,7 @@
-

4

+

{{ .Upload.CountOutside }}

Outside District

Potential geocoding errors

diff --git a/platform/pool.go b/platform/pool.go index 7f98ed88..3ca1045d 100644 --- a/platform/pool.go +++ b/platform/pool.go @@ -22,6 +22,7 @@ import ( type UploadPoolDetail struct { CountExisting int CountNew int + CountOutside int Created time.Time ID int32 Name string @@ -95,9 +96,12 @@ func GetUploadPoolDetail(ctx context.Context, organization_id int32, file_id int pools := make([]UploadPoolRow, 0) count_existing := 0 count_new := 0 + count_outside := 0 for _, r := range rows { if r.IsNew { count_new = count_new + 1 + } else if !r.IsInDistrict { + count_outside = count_outside + 1 } else { count_existing = count_existing + 1 } @@ -108,6 +112,7 @@ func GetUploadPoolDetail(ctx context.Context, organization_id int32, file_id int } return UploadPoolDetail{ CountExisting: count_existing, + CountOutside: count_outside, CountNew: count_new, Name: file.Name, Pools: pools,