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 30, 2024
1 parent e20cc00 commit 69c5395
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions roboflow/deployment.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,17 @@ 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(
"-n", "--tail", help="number of lines to show from the end of the logs (<= 50)", type=int, default=10)
"-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"
"-n", "--tail", help="number of lines to show from the end of the logs (<= 50)", type=int, default=10
)
deployment_log_parser.add_argument("-f", "--follow", help="follow log output", action="store_true")


def list_machine_types(args):
Expand Down Expand Up @@ -168,26 +168,27 @@ def get_deployment_log(args):
if api_key is None:
print("Please provide an api key")
exit(1)

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, args.tail, from_timestamp, to_timestamp)
status_code, msg = deploymentapi.get_deployment_log(
api_key, args.deployment_name, args.tail, from_timestamp, to_timestamp
)
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:
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 69c5395

Please sign in to comment.