crawlconfig api: add 'currCrawlState' and 'currCrawlTimeStart' to crawlconfig list api (already queried on backend) (#770)
* crawlconfig api: add 'currCrawlState' and 'currCrawlTimeStart' to crawlconfig list api (already queried on backend)
This commit is contained in:
parent
6b19f72a89
commit
821d29bd2a
@ -188,6 +188,9 @@ class CrawlConfigOut(CrawlConfig):
|
|||||||
"""Crawl Config Output, includes currCrawlId of running crawl"""
|
"""Crawl Config Output, includes currCrawlId of running crawl"""
|
||||||
|
|
||||||
currCrawlId: Optional[str]
|
currCrawlId: Optional[str]
|
||||||
|
currCrawlStartTime: Optional[datetime]
|
||||||
|
currCrawlState: Optional[str]
|
||||||
|
|
||||||
profileName: Optional[str]
|
profileName: Optional[str]
|
||||||
|
|
||||||
createdByName: Optional[str]
|
createdByName: Optional[str]
|
||||||
@ -470,7 +473,7 @@ class CrawlConfigOps:
|
|||||||
sort_direction: int = -1,
|
sort_direction: int = -1,
|
||||||
):
|
):
|
||||||
"""Get all crawl configs for an organization is a member of"""
|
"""Get all crawl configs for an organization is a member of"""
|
||||||
# pylint: disable=too-many-locals
|
# pylint: disable=too-many-locals,too-many-branches
|
||||||
# Zero-index page for query
|
# Zero-index page for query
|
||||||
page = page - 1
|
page = page - 1
|
||||||
skip = page * page_size
|
skip = page * page_size
|
||||||
@ -635,13 +638,13 @@ class CrawlConfigOps:
|
|||||||
)
|
)
|
||||||
running = {}
|
running = {}
|
||||||
for crawl in crawls:
|
for crawl in crawls:
|
||||||
running[crawl.cid] = crawl.id
|
running[crawl.cid] = crawl
|
||||||
|
|
||||||
configs = []
|
configs = []
|
||||||
for res in items:
|
for res in items:
|
||||||
config = CrawlConfigOut.from_dict(res)
|
config = CrawlConfigOut.from_dict(res)
|
||||||
# pylint: disable=invalid-name
|
# pylint: disable=invalid-name
|
||||||
config.currCrawlId = running.get(config.id)
|
self._add_curr_crawl_stats(config, running.get(config.id))
|
||||||
configs.append(config)
|
configs.append(config)
|
||||||
|
|
||||||
return configs, total
|
return configs, total
|
||||||
@ -667,7 +670,7 @@ class CrawlConfigOps:
|
|||||||
)
|
)
|
||||||
|
|
||||||
if len(crawls) == 1:
|
if len(crawls) == 1:
|
||||||
return crawls[0].id
|
return crawls[0]
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@ -684,6 +687,15 @@ class CrawlConfigOps:
|
|||||||
crawlconfig.lastCrawlState = crawl_stats["last_crawl_state"]
|
crawlconfig.lastCrawlState = crawl_stats["last_crawl_state"]
|
||||||
return crawlconfig
|
return crawlconfig
|
||||||
|
|
||||||
|
async def _add_curr_crawl_stats(self, crawlconfig, crawl):
|
||||||
|
"""Add stats from current running crawl, if any"""
|
||||||
|
if not crawl:
|
||||||
|
return
|
||||||
|
|
||||||
|
crawlconfig.currCrawlId = crawl.id
|
||||||
|
crawlconfig.currCrawlStartTime = crawl.started
|
||||||
|
crawlconfig.currCrawlState = crawl.state
|
||||||
|
|
||||||
async def get_crawl_config_out(self, cid: uuid.UUID, org: Organization):
|
async def get_crawl_config_out(self, cid: uuid.UUID, org: Organization):
|
||||||
"""Return CrawlConfigOut, including state of currently running crawl, if active
|
"""Return CrawlConfigOut, including state of currently running crawl, if active
|
||||||
also include inactive crawl configs"""
|
also include inactive crawl configs"""
|
||||||
@ -697,7 +709,9 @@ class CrawlConfigOps:
|
|||||||
)
|
)
|
||||||
|
|
||||||
if not crawlconfig.inactive:
|
if not crawlconfig.inactive:
|
||||||
crawlconfig.currCrawlId = await self.get_running_crawl(crawlconfig)
|
self._add_curr_crawl_stats(
|
||||||
|
crawlconfig, await self.get_running_crawl(crawlconfig)
|
||||||
|
)
|
||||||
|
|
||||||
user = await self.user_manager.get(crawlconfig.createdBy)
|
user = await self.user_manager.get(crawlconfig.createdBy)
|
||||||
# pylint: disable=invalid-name
|
# pylint: disable=invalid-name
|
||||||
|
Loading…
Reference in New Issue
Block a user