Skip to content

Commit

Permalink
Check if the App is running before stopping (#81)
Browse files Browse the repository at this point in the history
  • Loading branch information
Maksim committed Nov 4, 2020
1 parent ef1fbd1 commit cceb95c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ All notable changes to the `python-domino` library will be documented in this fi

* Started caching project_id
* Started using request session instead of creating new session every time
* Check if an App is running before attempting to stop it (in `app_unpublish`)

## 1.0.2

Expand Down
23 changes: 19 additions & 4 deletions domino/domino.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
from typing import Optional

from requests import HTTPError

from .routes import _Routes
from .helpers import *
from .http_request_manager import _HttpRequestManager
Expand Down Expand Up @@ -467,7 +471,7 @@ def collaborators_add(self, usernameOrEmail, message=""):

# App functions
def app_publish(self, unpublishRunningApps=True, hardwareTierId=None):
if unpublishRunningApps is True:
if unpublishRunningApps:
self.app_unpublish()
app_id = self._app_id
if app_id is None:
Expand All @@ -484,9 +488,20 @@ def app_unpublish(self):
app_id = self._app_id
if app_id is None:
return
url = self._routes.app_stop(app_id)
response = self.request_manager.post(url)
return response
status = self.__app_get_status(app_id)
self.log.debug(f"App {app_id} status={status}")
if status and status != 'Stopped' and status != 'Failed':
url = self._routes.app_stop(app_id)
response = self.request_manager.post(url)
return response

def __app_get_status(self, id) -> Optional[str]:
app_id = self._app_id
if app_id is None:
return None
url = self._routes.app_get(app_id)
response = self.request_manager.get(url).json()
return response.get('status', None)

def __app_create(self, name: str = "", hardware_tier_id: str = None) -> str:
"""
Expand Down
3 changes: 3 additions & 0 deletions domino/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ def app_start(self, app_id):

def app_stop(self, app_id):
return self.host + f'/v4/modelProducts/{app_id}/stop'

def app_get(self, app_id):
return f'{self.host}/v4/modelProducts/{app_id}'

# Hardware Tier URLs
def hardware_tiers_list(self, project_id):
Expand Down

0 comments on commit cceb95c

Please sign in to comment.