@@ -69,17 +69,17 @@ 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
76
deployment_log_parser .add_argument (
77
- "-d" , "--duration" , help = "duration of log (from now) in seconds" , type = int , default = 3600 )
78
- deployment_log_parser .add_argument (
79
- "-n" , "--tail" , help = "number of lines to show from the end of the logs (<= 50)" , type = int , default = 10 )
77
+ "-d" , "--duration" , help = "duration of log (from now) in seconds" , type = int , default = 3600
78
+ )
80
79
deployment_log_parser .add_argument (
81
- "-f " , "--follow " , help = "follow log output " , action = "store_true"
80
+ "-n " , "--tail " , help = "number of lines to show from the end of the logs (<= 50) " , type = int , default = 10
82
81
)
82
+ deployment_log_parser .add_argument ("-f" , "--follow" , help = "follow log output" , action = "store_true" )
83
83
84
84
85
85
def list_machine_types (args ):
@@ -168,26 +168,27 @@ def get_deployment_log(args):
168
168
if api_key is None :
169
169
print ("Please provide an api key" )
170
170
exit (1 )
171
-
171
+
172
172
to_timestamp = datetime .now ()
173
- from_timestamp = ( to_timestamp - timedelta (seconds = args .duration ) )
174
- log_ids = set () # to avoid duplicate logs
173
+ from_timestamp = to_timestamp - timedelta (seconds = args .duration )
174
+ log_ids = set () # to avoid duplicate logs
175
175
while True :
176
- status_code , msg = deploymentapi .get_deployment_log (api_key , args .deployment_name , args .tail , from_timestamp , to_timestamp )
176
+ status_code , msg = deploymentapi .get_deployment_log (
177
+ api_key , args .deployment_name , args .tail , from_timestamp , to_timestamp
178
+ )
177
179
if status_code != 200 :
178
180
print (f"{ status_code } : { msg } " )
179
181
exit (status_code )
180
182
181
- for log in msg [::- 1 ]: # logs are sorted by reversed timestamp
182
- if log [' insert_id' ] in log_ids :
183
+ for log in msg [::- 1 ]: # logs are sorted by reversed timestamp
184
+ if log [" insert_id" ] in log_ids :
183
185
continue
184
- log_ids .add (log [' insert_id' ])
186
+ log_ids .add (log [" insert_id" ])
185
187
print (f'[{ datetime .fromisoformat (log ["timestamp" ]).strftime ("%Y-%m-%d %H:%M:%S.%f" )} ] { log ["payload" ]} ' )
186
188
187
189
if not args .follow :
188
190
break
189
-
191
+
190
192
time .sleep (10 )
191
193
from_timestamp = to_timestamp
192
194
to_timestamp = datetime .now ()
193
-
0 commit comments