Skip to content

Commit cc1b1e5

Browse files
committed
replace MAS module during publish
1 parent 90a74e3 commit cc1b1e5

File tree

4 files changed

+2883
-16
lines changed

4 files changed

+2883
-16
lines changed

src/sasctl/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# Copyright © 2019, SAS Institute Inc., Cary, NC, USA. All Rights Reserved.
55
# SPDX-License-Identifier: Apache-2.0
66

7-
__version__ = '1.0.1'
7+
__version__ = '1.1.0'
88
__author__ = 'SAS'
99
__credits__ = ['Yi Jian Ching, Lucas De Paula, Peter Tobac, Chris Toth, Jon '
1010
'Walker']

src/sasctl/tasks.py

Lines changed: 44 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,13 @@
1313
import sys
1414
import warnings
1515

16+
from deprecated.sphinx import versionchanged
17+
1618
from . import utils
1719
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
2023
from .utils.pymas import PyMAS, from_pickle
2124

2225

@@ -211,6 +214,8 @@ def publish_model(model, destination, code=None, max_retries=60,
211214
212215
Returns
213216
-------
217+
RestObj
218+
The published model
214219
215220
Notes
216221
-----
@@ -225,24 +230,48 @@ def publish_model(model, destination, code=None, max_retries=60,
225230
:meth:`model_management.publish_model <.ModelManagement.publish_model>`
226231
:meth:`model_publish.publish_model <.ModelPublish.publish_model>`
227232
233+
234+
.. versionchanged:: 1.1.0
235+
Added `replace` option.
236+
228237
"""
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()
234254

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)
238261

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()
243264

265+
# Raise exception if still failing
244266
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())
246275

247276
log = request_link(job, 'publishingLog')
248277
msg = log.get('log').lstrip('SUCCESS===')

0 commit comments

Comments
 (0)