Skip to content

Commit

Permalink
always set state to running, don't depend on current status
Browse files Browse the repository at this point in the history
  • Loading branch information
ikreymer committed Aug 2, 2024
1 parent a25788c commit 973ed04
Showing 1 changed file with 18 additions and 21 deletions.
39 changes: 18 additions & 21 deletions backend/btrixcloud/operator/crawls.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
NON_RUNNING_STATES,
RUNNING_STATES,
RUNNING_AND_STARTING_ONLY,
RUNNING_AND_WAITING_ONLY,
RUNNING_AND_STARTING_STATES,
SUCCESSFUL_STATES,
FAILED_STATES,
Expand Down Expand Up @@ -808,27 +807,25 @@ async def sync_crawl_state(
status.resync_after = self.fast_retry_secs
return status

# set state to running (if not already)
if status.state not in RUNNING_STATES:
# if true (state is set), also run webhook
if await self.set_state(
"running",
status,
crawl,
allowed_from=["starting", "waiting_capacity"],
):
if not crawl.qa_source_crawl_id:
self.run_task(
self.event_webhook_ops.create_crawl_started_notification(
crawl.id, crawl.oid, scheduled=crawl.scheduled
)
# if true (state is set), also run webhook
if await self.set_state(
"running",
status,
crawl,
allowed_from=["starting", "waiting_capacity"],
):
if not crawl.qa_source_crawl_id:
self.run_task(
self.event_webhook_ops.create_crawl_started_notification(
crawl.id, crawl.oid, scheduled=crawl.scheduled
)
else:
self.run_task(
self.event_webhook_ops.create_qa_analysis_started_notification(
crawl.id, crawl.oid, crawl.qa_source_crawl_id
)
)
else:
self.run_task(
self.event_webhook_ops.create_qa_analysis_started_notification(
crawl.id, crawl.oid, crawl.qa_source_crawl_id
)
)

# update lastActiveTime if crawler is running
if crawler_running:
Expand Down Expand Up @@ -1400,7 +1397,7 @@ async def update_crawl_state(

if new_status:
await self.set_state(
new_status, status, crawl, allowed_from=RUNNING_AND_WAITING_ONLY
new_status, status, crawl, allowed_from=RUNNING_STATES
)

return status
Expand Down

0 comments on commit 973ed04

Please sign in to comment.