Skip to content

Commit

Permalink
Add unique suffix to task names, fallback to timestamp if unnamed
Browse files Browse the repository at this point in the history
  • Loading branch information
andylizf committed Oct 20, 2024
1 parent a27969b commit 8486352
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 7 deletions.
3 changes: 1 addition & 2 deletions sky/dag.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ def add(self, task: 'task.Task') -> None:
ValueError: If the task already exists in the DAG or if its name
is already used.
"""
if task.name is None:
task.name = common_utils.get_unique_task_name(task)
task.name = common_utils.get_unique_task_name(task)
if task.name in self._task_name_lookup:
with ux_utils.print_exception_no_traceback():
raise ValueError(
Expand Down
1 change: 0 additions & 1 deletion sky/serve/serve_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
if typing.TYPE_CHECKING:
import fastapi

from sky import task as task_lib
from sky.serve import replica_managers

SKY_SERVE_CONTROLLER_NAME: str = (
Expand Down
7 changes: 3 additions & 4 deletions sky/utils/common_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,11 +232,10 @@ def get_global_job_id(job_timestamp: str,
return global_job_id


def get_unique_task_name(_: 'task_lib.Task') -> str:
timestamp = int(time.time())
def get_unique_task_name(task: 'task_lib.Task') -> str:
name = task.name or f'task_{int(time.time())}'
unique_suffix = uuid.uuid4().hex[:6]
name = f'task_{timestamp}_{unique_suffix}'
return name
return f'{name}_{unique_suffix}'


class Backoff:
Expand Down

0 comments on commit 8486352

Please sign in to comment.