operator: adjust state transition rules to ensure 'running' state always accounted for in db (#1989)

don't rely on current status, always set state to running when running
to ensure idempotency in case of multiple calls
This commit is contained in:
Ilya Kreymer 2024-08-05 16:00:21 -07:00 committed by GitHub
parent 1c153dfd3c
commit 4a2725aaa6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -807,27 +807,25 @@ class CrawlOperator(BaseOperator):
status.resync_after = self.fast_retry_secs status.resync_after = self.fast_retry_secs
return status return status
# set state to running (if not already) # if true (state is set), also run webhook
if status.state not in RUNNING_STATES: if await self.set_state(
# if true (state is set), also run webhook "running",
if await self.set_state( status,
"running", crawl,
status, allowed_from=["starting", "waiting_capacity"],
crawl, ):
allowed_from=["starting", "waiting_capacity"], if not crawl.qa_source_crawl_id:
): self.run_task(
if not crawl.qa_source_crawl_id: self.event_webhook_ops.create_crawl_started_notification(
self.run_task( crawl.id, crawl.oid, scheduled=crawl.scheduled
self.event_webhook_ops.create_crawl_started_notification(
crawl.id, crawl.oid, scheduled=crawl.scheduled
)
) )
else: )
self.run_task( else:
self.event_webhook_ops.create_qa_analysis_started_notification( self.run_task(
crawl.id, crawl.oid, crawl.qa_source_crawl_id self.event_webhook_ops.create_qa_analysis_started_notification(
) crawl.id, crawl.oid, crawl.qa_source_crawl_id
) )
)
# update lastActiveTime if crawler is running # update lastActiveTime if crawler is running
if crawler_running: if crawler_running: