@@ -74,6 +74,7 @@ def add_deployment_parser(subparsers):
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 ("-d" , "--duration" , help = "duration of log (from now) in seconds" , type = int , default = 3600 )
77
+ deployment_log_parser .add_argument ("-n" , "--tail" , help = "number of lines to show from the end of the logs (<= 50)" , type = int , default = 10 )
77
78
deployment_log_parser .add_argument (
78
79
"-f" , "--follow" , help = "follow log output" , action = "store_true"
79
80
)
@@ -83,19 +84,19 @@ def list_machine_types(args):
83
84
api_key = args .api_key or load_roboflow_api_key (None )
84
85
if api_key is None :
85
86
print ("Please provide an api key" )
86
- return
87
+ exit ( 1 )
87
88
status_code , msg = deploymentapi .list_machine_types (api_key )
88
89
if status_code != 200 :
89
90
print (f"{ status_code } : { msg } " )
90
- return
91
+ exit ( status_code )
91
92
print (json .dumps (msg , indent = 2 ))
92
93
93
94
94
95
def add_deployment (args ):
95
96
api_key = args .api_key or load_roboflow_api_key (None )
96
97
if api_key is None :
97
98
print ("Please provide an api key" )
98
- return
99
+ exit ( 1 )
99
100
status_code , msg = deploymentapi .add_deployment (
100
101
api_key ,
101
102
# args.security_level,
@@ -108,7 +109,7 @@ def add_deployment(args):
108
109
109
110
if status_code != 200 :
110
111
print (f"{ status_code } : { msg } " )
111
- return
112
+ exit ( status_code )
112
113
else :
113
114
print (f"Deployment { args .deployment_name } created successfully" )
114
115
print (json .dumps (msg , indent = 2 ))
@@ -121,12 +122,12 @@ def get_deployment(args):
121
122
api_key = args .api_key or load_roboflow_api_key (None )
122
123
if api_key is None :
123
124
print ("Please provide an api key" )
124
- return
125
+ exit ( 1 )
125
126
while True :
126
127
status_code , msg = deploymentapi .get_deployment (api_key , args .deployment_name )
127
128
if status_code != 200 :
128
129
print (f"{ status_code } : { msg } " )
129
- return
130
+ exit ( status_code )
130
131
131
132
if (not args .wait_on_pending ) or msg ["status" ] != "pending" :
132
133
print (json .dumps (msg , indent = 2 ))
@@ -140,40 +141,40 @@ def list_deployment(args):
140
141
api_key = args .api_key or load_roboflow_api_key (None )
141
142
if api_key is None :
142
143
print ("Please provide an api key" )
143
- return
144
+ exit ( 1 )
144
145
status_code , msg = deploymentapi .list_deployment (api_key )
145
146
if status_code != 200 :
146
147
print (f"{ status_code } : { msg } " )
147
- return
148
+ exit ( status_code )
148
149
print (json .dumps (msg , indent = 2 ))
149
150
150
151
151
152
def delete_deployment (args ):
152
153
api_key = args .api_key or load_roboflow_api_key (None )
153
154
if api_key is None :
154
155
print ("Please provide an api key" )
155
- return
156
+ exit ( 1 )
156
157
status_code , msg = deploymentapi .delete_deployment (api_key , args .deployment_name )
157
158
if status_code != 200 :
158
159
print (f"{ status_code } : { msg } " )
159
- return
160
+ exit ( status_code )
160
161
print (json .dumps (msg , indent = 2 ))
161
162
162
163
163
164
def get_deployment_log (args ):
164
165
api_key = args .api_key or load_roboflow_api_key (None )
165
166
if api_key is None :
166
167
print ("Please provide an api key" )
167
- return
168
+ exit ( 1 )
168
169
169
170
to_timestamp = datetime .now ()
170
171
from_timestamp = (to_timestamp - timedelta (seconds = args .duration ))
171
172
log_ids = set () # to avoid duplicate logs
172
173
while True :
173
- status_code , msg = deploymentapi .get_deployment_log (api_key , args .deployment_name , from_timestamp , to_timestamp )
174
+ status_code , msg = deploymentapi .get_deployment_log (api_key , args .deployment_name , args . tail , from_timestamp , to_timestamp )
174
175
if status_code != 200 :
175
176
print (f"{ status_code } : { msg } " )
176
- return
177
+ exit ( status_code )
177
178
178
179
for log in msg [::- 1 ]: # logs are sorted by reversed timestamp
179
180
if log ['insert_id' ] in log_ids :
0 commit comments