@@ -69,14 +69,14 @@ def add_deployment_parser(subparsers):
69
69
deployment_delete_parser .set_defaults (func = delete_deployment )
70
70
deployment_delete_parser .add_argument ("-a" , "--api_key" , help = "api key" )
71
71
deployment_delete_parser .add_argument ("deployment_name" , help = "deployment name" )
72
-
72
+
73
73
deployment_log_parser .set_defaults (func = get_deployment_log )
74
74
deployment_log_parser .add_argument ("-a" , "--api_key" , help = "api key" )
75
75
deployment_log_parser .add_argument ("deployment_name" , help = "deployment name" )
76
- deployment_log_parser .add_argument ("-d" , "--duration" , help = "duration of log (from now) in seconds" , type = int , default = 3600 )
77
76
deployment_log_parser .add_argument (
78
- "-f " , "--follow " , help = "follow log output " , action = "store_true"
77
+ "-d " , "--duration " , help = "duration of log (from now) in seconds " , type = int , default = 3600
79
78
)
79
+ deployment_log_parser .add_argument ("-f" , "--follow" , help = "follow log output" , action = "store_true" )
80
80
81
81
82
82
def list_machine_types (args ):
@@ -165,26 +165,25 @@ def get_deployment_log(args):
165
165
if api_key is None :
166
166
print ("Please provide an api key" )
167
167
return
168
-
168
+
169
169
to_timestamp = datetime .now ()
170
- from_timestamp = ( to_timestamp - timedelta (seconds = args .duration ) )
171
- log_ids = set () # to avoid duplicate logs
170
+ from_timestamp = to_timestamp - timedelta (seconds = args .duration )
171
+ log_ids = set () # to avoid duplicate logs
172
172
while True :
173
173
status_code , msg = deploymentapi .get_deployment_log (api_key , args .deployment_name , from_timestamp , to_timestamp )
174
174
if status_code != 200 :
175
175
print (f"{ status_code } : { msg } " )
176
176
return
177
177
178
- for log in msg [::- 1 ]: # logs are sorted by reversed timestamp
179
- if log [' insert_id' ] in log_ids :
178
+ for log in msg [::- 1 ]: # logs are sorted by reversed timestamp
179
+ if log [" insert_id" ] in log_ids :
180
180
continue
181
- log_ids .add (log [' insert_id' ])
181
+ log_ids .add (log [" insert_id" ])
182
182
print (f'[{ datetime .fromisoformat (log ["timestamp" ]).strftime ("%Y-%m-%d %H:%M:%S.%f" )} ] { log ["payload" ]} ' )
183
183
184
184
if not args .follow :
185
185
break
186
-
186
+
187
187
time .sleep (10 )
188
188
from_timestamp = to_timestamp
189
189
to_timestamp = datetime .now ()
190
-
0 commit comments