Skip to content

Commit 8152223

Browse files
authored
concurrent crawls: filter concurrent crawls check (#2701)
ensure concurrent crawls check only counts running or waiting crawls only, not all existing crawljobs
1 parent 5b4fee7 commit 8152223

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

backend/btrixcloud/operator/crawls.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
TYPE_NON_RUNNING_STATES,
2020
TYPE_RUNNING_STATES,
2121
TYPE_ALL_CRAWL_STATES,
22-
NON_RUNNING_STATES,
2322
RUNNING_STATES,
2423
WAITING_STATES,
2524
RUNNING_AND_STARTING_ONLY,
@@ -757,22 +756,22 @@ async def can_start_new(
757756
if not max_crawls:
758757
return True
759758

760-
if len(data.related[CJS]) <= max_crawls:
761-
return True
762-
763759
name = data.parent.get("metadata", {}).get("name")
764760

765-
i = 0
761+
active_crawls = 0
762+
766763
for crawl_sorted in data.related[CJS].values():
767-
if crawl_sorted.get("status", {}).get("state") in NON_RUNNING_STATES:
764+
crawl_state = crawl_sorted.get("status", {}).get("state", "")
765+
766+
# don't count ourselves
767+
if crawl_sorted.get("metadata", {}).get("name") == name:
768768
continue
769769

770-
if crawl_sorted.get("metadata").get("name") == name:
771-
if i < max_crawls:
772-
return True
770+
if crawl_state in RUNNING_AND_WAITING_STATES:
771+
active_crawls += 1
773772

774-
break
775-
i += 1
773+
if active_crawls <= max_crawls:
774+
return True
776775

777776
await self.set_state(
778777
"waiting_org_limit", status, crawl, allowed_from=["starting"]

0 commit comments

Comments
 (0)