Skip to content

Commit 8e9d0b2

Browse files
[UX] Make sky logs <nonexistent job id> not error out. (skypilot-org#1617)
* Make `sky logs <nonexistent job id>` not error out. * Reformat
1 parent b42e01f commit 8e9d0b2

File tree

2 files changed

+16
-20
lines changed

2 files changed

+16
-20
lines changed

sky/skylet/job_lib.py

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -362,17 +362,14 @@ def _get_jobs_by_ids(job_ids: List[int]) -> List[Dict[str, Any]]:
362362
def update_job_status(job_owner: str,
363363
job_ids: List[int],
364364
silent: bool = False) -> List[JobStatus]:
365-
"""Updates and returns the job statuses matching our `JobStatus` semantics
365+
"""Updates and returns the job statuses matching our `JobStatus` semantics.
366366
367-
"True" statuses: this function queries `ray job status` and processes
368-
those results to match our semantics.
367+
This function queries `ray job status` and processes those results to match
368+
our semantics.
369369
370-
This function queries `ray job status` and processes those results to
371-
match our semantics.
372-
373-
Though we update job status actively in ray program and job cancelling,
374-
we still need this to handle staleness problem, caused by instance
375-
restarting and other corner cases (if any).
370+
Though we update job status actively in the generated ray program and
371+
during job cancelling, we still need this to handle the staleness problem,
372+
caused by instance restarting and other corner cases (if any).
376373
377374
This function should only be run on the remote instance with ray==2.0.1.
378375
"""
@@ -413,7 +410,8 @@ def update_job_status(job_owner: str,
413410
if status is None:
414411
original_status = get_status_no_lock(job_id)
415412
status = original_status
416-
if not original_status.is_terminal():
413+
if (original_status is not None and
414+
not original_status.is_terminal()):
417415
# The job may be stale, when the instance is restarted
418416
# (the ray redis is volatile). We need to reset the
419417
# status of the task to FAILED if its original status
@@ -665,14 +663,12 @@ def tail_logs(cls,
665663
job_id: Optional[int],
666664
spot_job_id: Optional[int],
667665
follow: bool = True) -> str:
666+
# pylint: disable=line-too-long
668667
code = [
669-
f'job_id = {job_id} if {job_id} is not None '
670-
'else job_lib.get_latest_job_id()',
668+
f'job_id = {job_id} if {job_id} is not None else job_lib.get_latest_job_id()',
671669
'run_timestamp = job_lib.get_run_timestamp(job_id)',
672-
(f'log_dir = os.path.join({constants.SKY_LOGS_DIRECTORY!r}, '
673-
'run_timestamp)'),
674-
(f'log_lib.tail_logs({job_owner!r},'
675-
f'job_id, log_dir, {spot_job_id!r}, follow={follow})'),
670+
f'log_dir = None if run_timestamp is None else os.path.join({constants.SKY_LOGS_DIRECTORY!r}, run_timestamp)',
671+
f'log_lib.tail_logs({job_owner!r}, job_id, log_dir, {spot_job_id!r}, follow={follow})',
676672
]
677673
return cls._build(code)
678674

sky/skylet/log_lib.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -383,14 +383,14 @@ def tail_logs(job_owner: str,
383383
job_str = f'job {job_id}'
384384
if spot_job_id is not None:
385385
job_str = f'spot job {spot_job_id}'
386-
logger.debug(f'Tailing logs for job, real job_id {job_id}, spot_job_id '
387-
f'{spot_job_id}.')
388-
logger.info(f'{colorama.Fore.YELLOW}Start streaming logs for {job_str}.'
389-
f'{colorama.Style.RESET_ALL}')
390386
if log_dir is None:
391387
print(f'{job_str.capitalize()} not found (see `sky queue`).',
392388
file=sys.stderr)
393389
return
390+
logger.debug(f'Tailing logs for job, real job_id {job_id}, spot_job_id '
391+
f'{spot_job_id}.')
392+
logger.info(f'{colorama.Fore.YELLOW}Start streaming logs for {job_str}.'
393+
f'{colorama.Style.RESET_ALL}')
394394
log_path = os.path.join(log_dir, 'run.log')
395395
log_path = os.path.expanduser(log_path)
396396

0 commit comments

Comments
 (0)