13
13
import sys
14
14
import warnings
15
15
16
+ from deprecated .sphinx import versionchanged
17
+
16
18
from . import utils
17
19
from .core import RestObj , get , get_link , request_link
18
- from .services import model_management as mm , model_publish as mp , \
19
- model_repository as mr
20
+ from .services import model_management as mm
21
+ from .services import model_publish as mp
22
+ from .services import model_repository as mr
20
23
from .utils .pymas import PyMAS , from_pickle
21
24
22
25
@@ -211,6 +214,8 @@ def publish_model(model, destination, code=None, max_retries=60,
211
214
212
215
Returns
213
216
-------
217
+ RestObj
218
+ The published model
214
219
215
220
Notes
216
221
-----
@@ -225,24 +230,48 @@ def publish_model(model, destination, code=None, max_retries=60,
225
230
:meth:`model_management.publish_model <.ModelManagement.publish_model>`
226
231
:meth:`model_publish.publish_model <.ModelPublish.publish_model>`
227
232
233
+
234
+ .. versionchanged:: 1.1.0
235
+ Added `replace` option.
236
+
228
237
"""
229
- # Submit a publishing request
230
- if code is None :
231
- publish_req = mm .publish_model (model , destination , ** kwargs )
232
- else :
233
- publish_req = mp .publish_model (model , destination , code = code , ** kwargs )
238
+ def submit_request ():
239
+ # Submit a publishing request
240
+ if code is None :
241
+ publish_req = mm .publish_model (model , destination , ** kwargs )
242
+ else :
243
+ publish_req = mp .publish_model (model , destination ,
244
+ code = code , ** kwargs )
245
+
246
+ # A successfully submitted request doesn't mean a successfully
247
+ # published model. Response for publish request includes link to
248
+ # check publish log
249
+ job = mr ._monitor_job (publish_req , max_retries = max_retries )
250
+ return job
251
+
252
+ # Submit and wait for status
253
+ job = submit_request ()
234
254
235
- # A successfully submitted request doesn't mean a successfully published model.
236
- # Response for publish request includes link to check publish log
237
- job = mr ._monitor_job (publish_req )
255
+ # If MAS publish failed and replace=True, attempt to delete the module
256
+ # and republish
257
+ if job .state .lower () == 'failed' and replace and \
258
+ job .destination .destinationType == 'microAnalyticService' :
259
+ from .services import microanalytic_score as mas
260
+ mas .delete_module (job .publishName )
238
261
239
- # Wait for status
240
- # If job failed & overwrite -> check type of destination
241
- # delete model from destination
242
- # publish again
262
+ # Resubmit the request
263
+ job = submit_request ()
243
264
265
+ # Raise exception if still failing
244
266
if job .state .lower () == 'failed' :
245
- pass
267
+ log = request_link (job , 'publishingLog' )
268
+ raise RuntimeError ("Failed to publish model '%s': %s"
269
+ % (model , log .log ))
270
+
271
+ # Raise exception if unknown status received
272
+ elif job .state .lower () != 'completed' :
273
+ raise RuntimeError ("Model publishing job in an unknown state: '%s'"
274
+ % job .state .lower ())
246
275
247
276
log = request_link (job , 'publishingLog' )
248
277
msg = log .get ('log' ).lstrip ('SUCCESS===' )
0 commit comments