Skip to content

Commit

Permalink
fix(pre_commit): 🎨 auto format pre-commit hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
pre-commit-ci[bot] committed Oct 21, 2024
1 parent 01a5f30 commit 713bc60
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions roboflow/deployment.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,14 @@ def add_deployment_parser(subparsers):
deployment_delete_parser.set_defaults(func=delete_deployment)
deployment_delete_parser.add_argument("-a", "--api_key", help="api key")
deployment_delete_parser.add_argument("deployment_name", help="deployment name")

deployment_log_parser.set_defaults(func=get_deployment_log)
deployment_log_parser.add_argument("-a", "--api_key", help="api key")
deployment_log_parser.add_argument("deployment_name", help="deployment name")
deployment_log_parser.add_argument("-d", "--duration", help="duration of log (from now) in seconds", type=int, default=3600)
deployment_log_parser.add_argument(
"-f", "--follow", help="follow log output", action="store_true"
"-d", "--duration", help="duration of log (from now) in seconds", type=int, default=3600
)
deployment_log_parser.add_argument("-f", "--follow", help="follow log output", action="store_true")


def list_machine_types(args):
Expand Down Expand Up @@ -165,26 +165,25 @@ def get_deployment_log(args):
if api_key is None:
print("Please provide an api key")
return

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

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

if not args.follow:
break

time.sleep(10)
from_timestamp = to_timestamp
to_timestamp = datetime.now()

0 comments on commit 713bc60

Please sign in to comment.