Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
KeplerC committed Jan 6, 2025
1 parent 8128ae1 commit 922fab0
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
25 changes: 18 additions & 7 deletions sky/backends/cloud_vm_ray_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -3885,18 +3885,29 @@ def sync_down_managed_job_logs(
if job_id is None:
# generate code to get the job_id
code = managed_jobs.ManagedJobCodeGen.get_job_ids_by_name(job_name)
returncode, run_timestamps, stderr = self.run_on_head(handle, code, stream_logs=False, require_outputs=True, separate_stderr=True)
subprocess_utils.handle_returncode(returncode, code, 'Failed to sync down logs.', stderr)
returncode, run_timestamps, stderr = self.run_on_head(
handle,
code,
stream_logs=False,
require_outputs=True,
separate_stderr=True)
subprocess_utils.handle_returncode(returncode, code,
'Failed to sync down logs.',
stderr)
# str'ed list to list
job_ids = common_utils.decode_payload(run_timestamps)
if not job_ids:
logger.info(f'{colorama.Fore.YELLOW}No matching job found{colorama.Style.RESET_ALL}')
logger.info(f'{colorama.Fore.YELLOW}'
'No matching job found'
f'{colorama.Style.RESET_ALL}')
return {}
elif len(job_ids) > 1:
logger.info(f'{colorama.Fore.YELLOW}Multiple jobs IDs found under the name {job_name}. Syncing down logs for all of them.{colorama.Style.RESET_ALL}')
return self.sync_down_logs(handle,
job_ids=job_ids,
local_dir=local_dir)
logger.info(
f'{colorama.Fore.YELLOW}'
f'Multiple jobs IDs found under the name {job_name}. '
'Syncing down logs for all of them.'
f'{colorama.Style.RESET_ALL}')
return self.sync_down_logs(handle, job_ids=job_ids, local_dir=local_dir)

def tail_serve_logs(self, handle: CloudVmRayResourceHandle,
service_name: str, target: serve_lib.ServiceComponent,
Expand Down
2 changes: 1 addition & 1 deletion sky/jobs/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,7 @@ def get_nonterminal_job_ids_by_name(name: Optional[str]) -> List[int]:
job_ids = [row[0] for row in rows if row[0] is not None]
return job_ids


def get_all_job_ids_by_name(name: Optional[str]) -> List[int]:
"""Get all job ids by name."""
name_filter = ''
Expand All @@ -575,7 +576,6 @@ def get_all_job_ids_by_name(name: Optional[str]) -> List[int]:
'(job_info.name IS NULL AND spot.task_name=(?)))')
field_values = [name, name]


# Left outer join is used here instead of join, because the job_info does
# not contain the managed jobs submitted before #1982.
with db_utils.safe_cursor(_DB_PATH) as cursor:
Expand Down
3 changes: 1 addition & 2 deletions sky/jobs/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -855,9 +855,8 @@ def cancel_job_by_name(cls, job_name: str) -> str:
""")
return cls._build(code)


@classmethod
def get_job_ids_by_name(cls, job_name: str) -> str:
def get_job_ids_by_name(cls, job_name: Optional[str]) -> str:
code = textwrap.dedent(f"""\
from sky.utils import common_utils
job_id = managed_job_state.get_all_job_ids_by_name({job_name!r})
Expand Down

0 comments on commit 922fab0

Please sign in to comment.