Skip to content

Commit

Permalink
Add superadmin endpoint to readd scheduled workflow cronjobs (#2430)
Browse files Browse the repository at this point in the history
Adds new superadmin-only `POST /orgs/all/crawlconfigs/reAddCronjobs`
endpoint to update/recreate scheduled workflow cronjobs across all orgs.
  • Loading branch information
tw4l authored Feb 27, 2025
1 parent da77b06 commit 3dc8c82
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions backend/btrixcloud/crawlconfigs.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
CrawlerChannel,
CrawlerChannels,
StartedResponse,
SuccessResponse,
CrawlConfigAddedResponse,
CrawlConfigSearchValues,
CrawlConfigUpdateResponse,
Expand Down Expand Up @@ -1036,6 +1037,21 @@ def get_warc_prefix(self, org: Organization, crawlconfig: CrawlConfig) -> str:
prefix = org.slug + "-" + name
return prefix[:80]

async def re_add_all_scheduled_cron_jobs(self):
"""Re-add all scheduled workflow cronjobs"""
match_query = {"schedule": {"$nin": ["", None]}, "inactive": {"$ne": True}}
async for config_dict in self.crawl_configs.find(match_query):
config = CrawlConfig.from_dict(config_dict)
try:
await self.crawl_manager.update_scheduled_job(config)
print(f"Updated cronjob for scheduled workflow {config.id}", flush=True)
# pylint: disable=broad-except
except Exception as err:
print(
f"Error updating cronjob for scheduled workflow {config.id}: {err}",
flush=True,
)


# ============================================================================
# pylint: disable=too-many-locals
Expand Down Expand Up @@ -1272,6 +1288,16 @@ async def make_inactive(cid: UUID, org: Organization = Depends(org_crawl_dep)):

return await ops.do_make_inactive(crawlconfig)

@app.post("/orgs/all/crawlconfigs/reAddCronjobs", response_model=SuccessResponse)
async def re_add_all_scheduled_cron_jobs(
user: User = Depends(user_dep),
):
if not user.is_superuser:
raise HTTPException(status_code=403, detail="Not Allowed")

asyncio.create_task(ops.re_add_all_scheduled_cron_jobs())
return {"success": True}

org_ops.router.include_router(router)

return ops

0 comments on commit 3dc8c82

Please sign in to comment.