Skip to content

Commit

Permalink
Remove crawl_type from optimize_pages bg job
Browse files Browse the repository at this point in the history
  • Loading branch information
tw4l committed Feb 18, 2025
1 parent 87f22dd commit 1986ea6
Show file tree
Hide file tree
Showing 6 changed files with 3 additions and 16 deletions.
4 changes: 0 additions & 4 deletions backend/btrixcloud/background_jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,14 +427,12 @@ async def create_re_add_org_pages_job(

async def create_optimize_crawl_pages_job(
self,
crawl_type: Optional[str] = None,
existing_job_id: Optional[str] = None,
):
"""Create job to optimize crawl pages"""

try:
job_id = await self.crawl_manager.run_optimize_pages_job(
crawl_type=crawl_type,
existing_job_id=existing_job_id,
)
if existing_job_id:
Expand All @@ -453,7 +451,6 @@ async def create_optimize_crawl_pages_job(
else:
optimize_pages_job = OptimizePagesJob(
id=job_id,
crawl_type=crawl_type,
started=dt_now(),
)

Expand Down Expand Up @@ -661,7 +658,6 @@ async def retry_background_job(

if job.type == BgJobType.OPTIMIZE_PAGES:
await self.create_optimize_crawl_pages_job(
job.crawl_type,
existing_job_id=job_id,
)
return {"success": True}
Expand Down
2 changes: 0 additions & 2 deletions backend/btrixcloud/crawlmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ async def run_re_add_org_pages_job(

async def run_optimize_pages_job(
self,
crawl_type: Optional[str] = None,
existing_job_id: Optional[str] = None,
) -> str:
"""run job to recalculate storage stats for the org"""
Expand All @@ -183,7 +182,6 @@ async def run_optimize_pages_job(
job_id,
job_type=BgJobType.OPTIMIZE_PAGES.value,
migration_job=True,
crawl_type=crawl_type,
)

async def _run_bg_job_with_ops_classes(
Expand Down
2 changes: 1 addition & 1 deletion backend/btrixcloud/main_bg.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ async def main():
# Run job (generic)
if job_type == BgJobType.OPTIMIZE_PAGES:
try:
await page_ops.optimize_crawl_pages(version=2, crawl_type=crawl_type)
await page_ops.optimize_crawl_pages(version=2)
return 0
# pylint: disable=broad-exception-caught
except Exception:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ async def migrate_up(self):
return

try:
await self.background_job_ops.create_optimize_crawl_pages_job(
crawl_type="crawl"
)
await self.background_job_ops.create_optimize_crawl_pages_job()
# pylint: disable=broad-exception-caught
except Exception as err:
print(
Expand Down
1 change: 0 additions & 1 deletion backend/btrixcloud/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2607,7 +2607,6 @@ class OptimizePagesJob(BackgroundJob):
"""Model for tracking jobs to optimize pages across all orgs"""

type: Literal[BgJobType.OPTIMIZE_PAGES] = BgJobType.OPTIMIZE_PAGES
crawl_type: Optional[str] = None


# ============================================================================
Expand Down
6 changes: 1 addition & 5 deletions backend/btrixcloud/pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -978,15 +978,11 @@ async def set_archived_item_page_counts(self, crawl_id: str):
{"$set": {"uniquePageCount": unique_page_count, "pageCount": page_count}},
)

async def optimize_crawl_pages(
self, version: int = 2, crawl_type: Optional[str] = None
):
async def optimize_crawl_pages(self, version: int = 2):
"""Iterate through crawls, optimizing pages"""
while True:
# Pull new crawl and set isMigrating
match_query = {"version": {"$ne": version}, "isMigrating": {"$ne": True}}
if crawl_type in ("crawl", "upload"):
match_query["type"] = crawl_type

next_crawl = await self.crawls.find_one_and_update(
match_query, {"$set": {"isMigrating": True}}
Expand Down

0 comments on commit 1986ea6

Please sign in to comment.