Skip to content

Commit b7a981a

Browse files
committed
Only send auto-paused emails once
1 parent bb8d616 commit b7a981a

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,
@@ -1626,13 +1627,16 @@ async def update_crawl_state(
16261627
allowed_from=RUNNING_AND_WAITING_STATES,
16271628
)
16281629

1629-
# TODO: This is reached several times, so make it idempotent
1630-
if paused_state != "paused":
1630+
if (
1631+
paused_state in AUTO_PAUSED_STATES
1632+
and not status.autoPausedEmailsSent
1633+
):
16311634
await self.crawl_ops.notify_org_admins_of_auto_paused_crawl(
16321635
paused_reason=paused_state,
16331636
cid=crawl.cid,
16341637
org=crawl.org,
16351638
)
1639+
status.autoPausedEmailsSent = True
16361640

16371641
return status
16381642

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)