Skip to content

Commit fb2fa0c

Browse files
committed
set correct last_log_timestamp
1 parent e20cc00 commit fb2fa0c

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

roboflow/adapters/deploymentapi.py

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

5959

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}"
60+
def get_deployment_log(api_key, deployment_name, from_timestamp=None, to_timestamp=None, max_entries=-1):
61+
url = f"{DEDICATED_DEPLOYMENT_URL}/get_log?api_key={api_key}&deployment_name={deployment_name}"
6262
if from_timestamp is not None:
6363
url += f"&from_timestamp={from_timestamp.isoformat()}"
6464
if to_timestamp is not None:
6565
url += f"&to_timestamp={to_timestamp.isoformat()}"
66+
if max_entries > 0:
67+
url += f"&max_entries={max_entries}"
6668
response = requests.get(url)
6769
if response.status_code != 200:
6870
return response.status_code, response.text

roboflow/deployment.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -171,23 +171,28 @@ def get_deployment_log(args):
171171

172172
to_timestamp = datetime.now()
173173
from_timestamp = (to_timestamp - timedelta(seconds = args.duration))
174+
last_log_timestamp = from_timestamp
174175
log_ids = set() # to avoid duplicate logs
176+
max_entries = args.tail
175177
while True:
176-
status_code, msg = deploymentapi.get_deployment_log(api_key, args.deployment_name, args.tail, from_timestamp, to_timestamp)
178+
status_code, msg = deploymentapi.get_deployment_log(api_key, args.deployment_name, from_timestamp, to_timestamp, max_entries)
177179
if status_code != 200:
178180
print(f"{status_code}: {msg}")
179181
exit(status_code)
180182

181183
for log in msg[::-1]: # logs are sorted by reversed timestamp
182-
if log['insert_id'] in log_ids:
184+
log_timestamp = datetime.fromisoformat(log["timestamp"]).replace(tzinfo=None)
185+
if (log['insert_id'] in log_ids) or (log_timestamp < last_log_timestamp):
183186
continue
184187
log_ids.add(log['insert_id'])
185-
print(f'[{datetime.fromisoformat(log["timestamp"]).strftime("%Y-%m-%d %H:%M:%S.%f")}] {log["payload"]}')
188+
last_log_timestamp = log_timestamp
189+
print(f'[{log_timestamp.strftime("%Y-%m-%d %H:%M:%S.%f")}] {log["payload"]}')
186190

187191
if not args.follow:
188192
break
189193

190194
time.sleep(10)
191-
from_timestamp = to_timestamp
195+
from_timestamp = last_log_timestamp
192196
to_timestamp = datetime.now()
197+
max_entries = 300 # only set max_entries for the first request
193198

0 commit comments

Comments
 (0)