Skip to content

Commit b727750

Browse files
committed
Adds a decorator to generate watch command for the run operation.
1 parent c46e8a3 commit b727750

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

ads/opctl/decorator/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8; -*-
3+
4+
# Copyright (c) 2023 Oracle and its affiliates.
5+
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/

ads/opctl/decorator/common.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8; -*-
3+
4+
# Copyright (c) 2023 Oracle and/or its affiliates.
5+
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
6+
7+
from typing import Dict, Callable
8+
from functools import wraps
9+
10+
RUN_ID_FIELD = "run_id"
11+
12+
def print_watch_command(func: callable)->Callable:
13+
"""The decorator to help build the `opctl watch` command."""
14+
@wraps(func)
15+
def wrapper(*args, **kwargs)->Dict:
16+
result = func(*args, **kwargs)
17+
if result and isinstance(result, Dict) and RUN_ID_FIELD in result:
18+
msg_header = (
19+
f"{'*' * 40} To monitor the progress of a task, execute the following command {'*' * 40}"
20+
)
21+
print(msg_header)
22+
print(f"ads opctl watch {result[RUN_ID_FIELD]}")
23+
print("*" * len(msg_header))
24+
return result
25+
return wrapper

0 commit comments

Comments
 (0)