Repository navigation
fix(opportunity): retry add_connect_users on transient ConnectID outages - #1854
Conversation
Co-authored-by: sentry[bot] <39604003+sentry[bot]@users.noreply.github.com>
|
Important Review skippedBot user detected. To trigger a single review, invoke the
|
|
✅ OpenCodeReview: Review complete: 0 finding(s) across 2 selected item(s). |
| logger.warning( | ||
| "ConnectID unavailable while inviting %d users to opportunity %s (attempt %d): %s", | ||
| len(user_list), | ||
| opportunity_id, | ||
| self.request.retries + 1, | ||
| exc, | ||
| ) | ||
| raise self.retry(exc=exc, countdown=min(300, 30 * 2**self.request.retries)) |
There was a problem hiding this comment.
add_connect_users is invoked via .delay() from request-handling views (e.g. OpportunityEdit.form_valid), with no try/except around the call. With CELERY_TASK_ALWAYS_EAGER=True (the default in local/dev settings and several test modules), this task executes synchronously inside the request. Calling self.retry(..., countdown=...) in eager mode does not actually wait; it raises celery.exceptions.Retry immediately, which will propagate up into the view instead of being handled as a normal task failure. A similar case in this same file (_retry_or_fail_finance_request) explicitly guards against this with not task.request.is_eager before retrying - the same guard seems to be missing here.
Suggestion:
| logger.warning( | |
| "ConnectID unavailable while inviting %d users to opportunity %s (attempt %d): %s", | |
| len(user_list), | |
| opportunity_id, | |
| self.request.retries + 1, | |
| exc, | |
| ) | |
| raise self.retry(exc=exc, countdown=min(300, 30 * 2**self.request.retries)) | |
| logger.warning( | |
| "ConnectID unavailable while inviting %d users to opportunity %s (attempt %d): %s", | |
| len(user_list), | |
| opportunity_id, | |
| self.request.retries + 1, | |
| exc, | |
| ) | |
| if self.request.is_eager: | |
| raise | |
| raise self.retry(exc=exc, countdown=min(300, 30 * 2**self.request.retries)) |
| self.request.retries + 1, | ||
| exc, | ||
| ) | ||
| raise self.retry(exc=exc, countdown=min(300, 30 * 2**self.request.retries)) |
There was a problem hiding this comment.
The backoff calculation uses inline magic numbers (30 and 300) that aren't named constants, unlike CONNECTID_TRANSIENT_STATUS_CODES and ADD_CONNECT_USERS_MAX_RETRIES defined above. Extracting them (e.g. ADD_CONNECT_USERS_RETRY_BASE_SECONDS / ADD_CONNECT_USERS_RETRY_MAX_SECONDS) would make the backoff schedule easier to tune and reason about.
Suggestion:
| raise self.retry(exc=exc, countdown=min(300, 30 * 2**self.request.retries)) | |
| countdown = min(ADD_CONNECT_USERS_RETRY_MAX_SECONDS, ADD_CONNECT_USERS_RETRY_BASE_SECONDS * 2**self.request.retries) | |
| raise self.retry(exc=exc, countdown=countdown) |
Product Description
Opportunity invites are no longer dropped when ConnectID is temporarily unavailable, such as during a proxy cutover or deployment.
Technical Summary
What was changed and why
When ConnectID is temporarily unavailable (for instance, during a proxy cutover or deployment where
kamal-proxyreturns HTTP 404/5xx before the app container becomes healthy),add_connect_usersfailed with an uncaughthttpx.HTTPStatusErrorand dropped opportunity invites.This PR updates
add_connect_usersto:httpx.TransportErrorand HTTP status codes 404, 502, 503, 504) as retryable errors via a dedicated_fetch_users_or_retryhelper.ADD_CONNECT_USERS_RETRY_BASE_SECONDSandADD_CONNECT_USERS_RETRY_MAX_SECONDS).task.request.is_eagerbefore callingself.retryto prevent Celery'sRetryexception from leaking when run synchronously (such as during tests or in development underCELERY_TASK_ALWAYS_EAGER).Documentation
None
Deployment
Fixes COMMCARE-CONNECT-14K
@sentry <feedback>: Autofix iterates on these changes@sentry stop iterating: Autofix stops iterating on this run