Skip to content

Commit

Permalink
set correct last_log_timestamp
Browse files Browse the repository at this point in the history
  • Loading branch information
PacificDou committed Oct 30, 2024
1 parent e20cc00 commit fb2fa0c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
6 changes: 4 additions & 2 deletions roboflow/adapters/deploymentapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,14 @@ def list_machine_types(api_key):
return response.status_code, response.json()


def get_deployment_log(api_key, deployment_name, max_entries, from_timestamp=None, to_timestamp=None):
url = f"{DEDICATED_DEPLOYMENT_URL}/get_log?api_key={api_key}&deployment_name={deployment_name}&max_entries={max_entries}"
def get_deployment_log(api_key, deployment_name, from_timestamp=None, to_timestamp=None, max_entries=-1):
url = f"{DEDICATED_DEPLOYMENT_URL}/get_log?api_key={api_key}&deployment_name={deployment_name}"
if from_timestamp is not None:
url += f"&from_timestamp={from_timestamp.isoformat()}"
if to_timestamp is not None:
url += f"&to_timestamp={to_timestamp.isoformat()}"
if max_entries > 0:
url += f"&max_entries={max_entries}"
response = requests.get(url)
if response.status_code != 200:
return response.status_code, response.text
Expand Down
13 changes: 9 additions & 4 deletions roboflow/deployment.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,23 +171,28 @@ def get_deployment_log(args):

to_timestamp = datetime.now()
from_timestamp = (to_timestamp - timedelta(seconds = args.duration))
last_log_timestamp = from_timestamp
log_ids = set() # to avoid duplicate logs
max_entries = args.tail
while True:
status_code, msg = deploymentapi.get_deployment_log(api_key, args.deployment_name, args.tail, from_timestamp, to_timestamp)
status_code, msg = deploymentapi.get_deployment_log(api_key, args.deployment_name, from_timestamp, to_timestamp, max_entries)
if status_code != 200:
print(f"{status_code}: {msg}")
exit(status_code)

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

if not args.follow:
break

time.sleep(10)
from_timestamp = to_timestamp
from_timestamp = last_log_timestamp
to_timestamp = datetime.now()
max_entries = 300 # only set max_entries for the first request

0 comments on commit fb2fa0c

Please sign in to comment.