Skip to content

Commit a6098c0

Browse files
committed
add support for -n in log
1 parent 01a5f30 commit a6098c0

File tree

2 files changed

+16
-15
lines changed

2 files changed

+16
-15
lines changed

roboflow/adapters/deploymentapi.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ def list_machine_types(api_key):
5757
return response.status_code, response.json()
5858

5959

60-
def get_deployment_log(api_key, deployment_name, from_timestamp=None, to_timestamp=None):
61-
url = f"{DEDICATED_DEPLOYMENT_URL}/get_log?api_key={api_key}&deployment_name={deployment_name}"
60+
def get_deployment_log(api_key, deployment_name, max_entries, from_timestamp=None, to_timestamp=None):
61+
url = f"{DEDICATED_DEPLOYMENT_URL}/get_log?api_key={api_key}&deployment_name={deployment_name}&max_entries={max_entries}"
6262
if from_timestamp is not None:
6363
url += f"&from_timestamp={from_timestamp.isoformat()}"
6464
if to_timestamp is not None:

roboflow/deployment.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ def add_deployment_parser(subparsers):
7474
deployment_log_parser.add_argument("-a", "--api_key", help="api key")
7575
deployment_log_parser.add_argument("deployment_name", help="deployment name")
7676
deployment_log_parser.add_argument("-d", "--duration", help="duration of log (from now) in seconds", type=int, default=3600)
77+
deployment_log_parser.add_argument("-n", "--tail", help="number of lines to show from the end of the logs (<= 50)", type=int, default=10)
7778
deployment_log_parser.add_argument(
7879
"-f", "--follow", help="follow log output", action="store_true"
7980
)
@@ -83,19 +84,19 @@ def list_machine_types(args):
8384
api_key = args.api_key or load_roboflow_api_key(None)
8485
if api_key is None:
8586
print("Please provide an api key")
86-
return
87+
exit(1)
8788
status_code, msg = deploymentapi.list_machine_types(api_key)
8889
if status_code != 200:
8990
print(f"{status_code}: {msg}")
90-
return
91+
exit(status_code)
9192
print(json.dumps(msg, indent=2))
9293

9394

9495
def add_deployment(args):
9596
api_key = args.api_key or load_roboflow_api_key(None)
9697
if api_key is None:
9798
print("Please provide an api key")
98-
return
99+
exit(1)
99100
status_code, msg = deploymentapi.add_deployment(
100101
api_key,
101102
# args.security_level,
@@ -108,7 +109,7 @@ def add_deployment(args):
108109

109110
if status_code != 200:
110111
print(f"{status_code}: {msg}")
111-
return
112+
exit(status_code)
112113
else:
113114
print(f"Deployment {args.deployment_name} created successfully")
114115
print(json.dumps(msg, indent=2))
@@ -121,12 +122,12 @@ def get_deployment(args):
121122
api_key = args.api_key or load_roboflow_api_key(None)
122123
if api_key is None:
123124
print("Please provide an api key")
124-
return
125+
exit(1)
125126
while True:
126127
status_code, msg = deploymentapi.get_deployment(api_key, args.deployment_name)
127128
if status_code != 200:
128129
print(f"{status_code}: {msg}")
129-
return
130+
exit(status_code)
130131

131132
if (not args.wait_on_pending) or msg["status"] != "pending":
132133
print(json.dumps(msg, indent=2))
@@ -140,40 +141,40 @@ def list_deployment(args):
140141
api_key = args.api_key or load_roboflow_api_key(None)
141142
if api_key is None:
142143
print("Please provide an api key")
143-
return
144+
exit(1)
144145
status_code, msg = deploymentapi.list_deployment(api_key)
145146
if status_code != 200:
146147
print(f"{status_code}: {msg}")
147-
return
148+
exit(status_code)
148149
print(json.dumps(msg, indent=2))
149150

150151

151152
def delete_deployment(args):
152153
api_key = args.api_key or load_roboflow_api_key(None)
153154
if api_key is None:
154155
print("Please provide an api key")
155-
return
156+
exit(1)
156157
status_code, msg = deploymentapi.delete_deployment(api_key, args.deployment_name)
157158
if status_code != 200:
158159
print(f"{status_code}: {msg}")
159-
return
160+
exit(status_code)
160161
print(json.dumps(msg, indent=2))
161162

162163

163164
def get_deployment_log(args):
164165
api_key = args.api_key or load_roboflow_api_key(None)
165166
if api_key is None:
166167
print("Please provide an api key")
167-
return
168+
exit(1)
168169

169170
to_timestamp = datetime.now()
170171
from_timestamp = (to_timestamp - timedelta(seconds = args.duration))
171172
log_ids = set() # to avoid duplicate logs
172173
while True:
173-
status_code, msg = deploymentapi.get_deployment_log(api_key, args.deployment_name, from_timestamp, to_timestamp)
174+
status_code, msg = deploymentapi.get_deployment_log(api_key, args.deployment_name, args.tail, from_timestamp, to_timestamp)
174175
if status_code != 200:
175176
print(f"{status_code}: {msg}")
176-
return
177+
exit(status_code)
177178

178179
for log in msg[::-1]: # logs are sorted by reversed timestamp
179180
if log['insert_id'] in log_ids:

0 commit comments

Comments
 (0)