From 28f1c815d0410e6f488cec654c834e53621142ee Mon Sep 17 00:00:00 2001 From: Tessa Walsh Date: Mon, 22 May 2023 19:06:37 -0400 Subject: [PATCH] Add crawlSuccessfulCount to workflows (#871) --- backend/btrixcloud/crawlconfigs.py | 10 ++++++++-- backend/test/test_crawlconfigs.py | 2 ++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/backend/btrixcloud/crawlconfigs.py b/backend/btrixcloud/crawlconfigs.py index cfd88f52..925b839e 100644 --- a/backend/btrixcloud/crawlconfigs.py +++ b/backend/btrixcloud/crawlconfigs.py @@ -175,13 +175,14 @@ class CrawlConfig(CrawlConfigCore): colls: Optional[List[str]] = [] - crawlAttemptCount: Optional[int] = 0 - inactive: Optional[bool] = False rev: int = 0 + crawlAttemptCount: Optional[int] = 0 crawlCount: Optional[int] = 0 + crawlSuccessfulCount: Optional[int] = 0 + totalSize: Optional[int] = 0 lastCrawlId: Optional[str] @@ -944,6 +945,7 @@ async def update_config_crawl_stats(crawl_configs, crawls, cid: uuid.UUID): """ update_query = { "crawlCount": 0, + "crawlSuccessfulCount": 0, "totalSize": 0, "lastCrawlId": None, "lastCrawlStartTime": None, @@ -961,6 +963,10 @@ async def update_config_crawl_stats(crawl_configs, crawls, cid: uuid.UUID): if results: update_query["crawlCount"] = len(results) + update_query["crawlSuccessfulCount"] = len( + [res for res in results if res["state"] not in ("canceled", "failed")] + ) + last_crawl = results[0] last_crawl_finished = last_crawl.get("finished") diff --git a/backend/test/test_crawlconfigs.py b/backend/test/test_crawlconfigs.py index ba4ec868..e1d6f257 100644 --- a/backend/test/test_crawlconfigs.py +++ b/backend/test/test_crawlconfigs.py @@ -226,6 +226,7 @@ def test_workflow_total_size_and_last_crawl_stats( if last_crawl_id and last_crawl_id in (admin_crawl_id, crawler_crawl_id): assert workflow["totalSize"] > 0 assert workflow["crawlCount"] > 0 + assert workflow["crawlSuccessfulCount"] > 0 assert workflow["lastCrawlId"] assert workflow["lastCrawlStartTime"] @@ -249,6 +250,7 @@ def test_workflow_total_size_and_last_crawl_stats( data = r.json() assert data["totalSize"] > 0 assert data["crawlCount"] > 0 + assert data["crawlSuccessfulCount"] > 0 assert data["lastCrawlId"] assert data["lastCrawlStartTime"]