Skip to content

Commit c212501

Browse files
authored
Unsuspend Job when CrawlJob is finished (#2489)
Fixes #2488 Adds a k8s api cal to set `suspend=false` on Job when associated CrawlJob is finished.
1 parent 1a9d3d6 commit c212501

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

backend/btrixcloud/k8sapi.py

+12
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,18 @@ async def _patch_job(self, crawl_id, body, pluraltype="crawljobs") -> dict:
280280
traceback.print_exc()
281281
return {"error": str(exc)}
282282

283+
async def unsuspend_k8s_job(self, name) -> dict:
284+
"""unsuspend k8s Job"""
285+
try:
286+
await self.batch_api.patch_namespaced_job(
287+
name=name, namespace=self.namespace, body={"spec": {"suspend": False}}
288+
)
289+
return {"success": True}
290+
# pylint: disable=broad-except
291+
except Exception as exc:
292+
traceback.print_exc()
293+
return {"error": str(exc)}
294+
283295
async def print_pod_logs(self, pod_names, lines=100):
284296
"""print pod logs"""
285297
for pod in pod_names:

backend/btrixcloud/operator/cronjobs.py

+2
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ def get_finished_response(
4242
"completionTime": finished,
4343
}
4444

45+
self.run_task(self.k8s.unsuspend_k8s_job(metadata.get("name")))
46+
4547
return MCDecoratorSyncResponse(
4648
attachments=[],
4749
# set on job to match default behavior when job finishes

0 commit comments

Comments
 (0)