@@ -69,17 +69,17 @@ def add_deployment_parser(subparsers):
6969 deployment_delete_parser .set_defaults (func = delete_deployment )
7070 deployment_delete_parser .add_argument ("-a" , "--api_key" , help = "api key" )
7171 deployment_delete_parser .add_argument ("deployment_name" , help = "deployment name" )
72-
72+
7373 deployment_log_parser .set_defaults (func = get_deployment_log )
7474 deployment_log_parser .add_argument ("-a" , "--api_key" , help = "api key" )
7575 deployment_log_parser .add_argument ("deployment_name" , help = "deployment name" )
7676 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+ )
8079 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
8281 )
82+ deployment_log_parser .add_argument ("-f" , "--follow" , help = "follow log output" , action = "store_true" )
8383
8484
8585def list_machine_types (args ):
@@ -168,26 +168,27 @@ def get_deployment_log(args):
168168 if api_key is None :
169169 print ("Please provide an api key" )
170170 exit (1 )
171-
171+
172172 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
175175 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+ )
177179 if status_code != 200 :
178180 print (f"{ status_code } : { msg } " )
179181 exit (status_code )
180182
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 :
183185 continue
184- log_ids .add (log [' insert_id' ])
186+ log_ids .add (log [" insert_id" ])
185187 print (f'[{ datetime .fromisoformat (log ["timestamp" ]).strftime ("%Y-%m-%d %H:%M:%S.%f" )} ] { log ["payload" ]} ' )
186188
187189 if not args .follow :
188190 break
189-
191+
190192 time .sleep (10 )
191193 from_timestamp = to_timestamp
192194 to_timestamp = datetime .now ()
193-
0 commit comments