Skip to content

Commit 1472129

Browse files
committed
Only send auto-paused emails once
1 parent c6a4765 commit 1472129

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

backend/btrixcloud/models.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ class UserOrgInfoOut(BaseModel):
244244
"paused_time_quota_reached",
245245
"paused_org_readonly",
246246
]
247+
AUTO_PAUSED_STATES = get_args(TYPE_AUTO_PAUSED_STATES)
247248

248249
TYPE_PAUSED_STATES = Literal[
249250
TYPE_MANUALLY_PAUSED_STATES,

backend/btrixcloud/operator/crawls.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
TYPE_RUNNING_STATES,
2323
TYPE_ALL_CRAWL_STATES,
2424
TYPE_PAUSED_STATES,
25+
AUTO_PAUSED_STATES,
2526
RUNNING_STATES,
2627
WAITING_STATES,
2728
RUNNING_AND_STARTING_ONLY,
@@ -1638,13 +1639,16 @@ async def update_crawl_state(
16381639
allowed_from=RUNNING_AND_WAITING_STATES,
16391640
)
16401641

1641-
# TODO: This is reached several times, so make it idempotent
1642-
if paused_state != "paused":
1642+
if (
1643+
paused_state in AUTO_PAUSED_STATES
1644+
and not status.autoPausedEmailsSent
1645+
):
16431646
await self.crawl_ops.notify_org_admins_of_auto_paused_crawl(
16441647
paused_reason=paused_state,
16451648
cid=crawl.cid,
16461649
org=crawl.org,
16471650
)
1651+
status.autoPausedEmailsSent = True
16481652

16491653
return status
16501654

backend/btrixcloud/operator/models.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,3 +257,6 @@ class CrawlStatus(BaseModel):
257257

258258
# last state
259259
last_state: TYPE_ALL_CRAWL_STATES = Field(default="starting", exclude=True)
260+
261+
# email sent to org admins because crawl was auto-paused
262+
autoPausedEmailsSent: bool = False

0 commit comments

Comments
 (0)