Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 768 | Gateway: hotfix for update status command #769

Merged
merged 1 commit into from
Jul 13, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 26 additions & 10 deletions gateway/api/management/commands/update_jobs_statuses.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Cleanup resources command."""
import logging
import time

from django.core.management.base import BaseCommand
from ray.dashboard.modules.job.sdk import JobSubmissionClient
Expand All @@ -22,20 +23,35 @@ def handle(self, *args, **options):
updated_jobs_counter = 0
for job in Job.objects.filter(status__in=Job.RUNNING_STATES):
if job.compute_resource:
try:
ray_client = JobSubmissionClient(job.compute_resource.host)
# update job logs
job.logs = ray_client.get_job_logs(job.ray_job_id)
# update job status
ray_job_status = ray_job_status_to_model_job_status(
ray_client.get_job_status(job.ray_job_id)
)
except (ConnectionError, RuntimeError):
success = False
ray_job_status = Job.PENDING
retries_left = 10
while not success and retries_left > 0:
try:
ray_client = JobSubmissionClient(job.compute_resource.host)
# update job logs
job.logs = ray_client.get_job_logs(job.ray_job_id)
# update job status
ray_job_status = ray_job_status_to_model_job_status(
ray_client.get_job_status(job.ray_job_id)
)
success = True
except (ConnectionError, RuntimeError) as runtime_error:
logger.error(
"Runtime error during job status update: %s", runtime_error
)
retries_left -= 1
logger.error("Retries left %s", retries_left)
time.sleep(1)

if not success:
kill_ray_cluster(job.compute_resource.title)
job.compute_resource.delete()
job.compute_resource = None
ray_job_status = Job.FAILED
job.logs = "Something went wrong during compute resource instance."
job.logs = (
f"{job.logs}\nSomething went wrong during updating job status."
)

if ray_job_status != job.status:
logger.info(
Expand Down