Fixing up status checking

This commit is contained in:
Adolfo Gómez García 2021-06-23 17:53:13 +02:00
parent 83a407d350
commit 2834120b35
2 changed files with 25 additions and 19 deletions

View File

@ -400,6 +400,8 @@ def enableService(request: 'ExtendedHttpRequestWithUser', idService: str, idTran
userService, trans = res[1], res[3]
userService.setProperty('accesedByClient', '0') # Reset accesed property to
typeTrans = trans.getType()
error = '' # No error

View File

@ -156,27 +156,31 @@ def userServiceStatus(
'''
ip: typing.Union[str, None, bool]
userService = None
try:
(
ip,
userService,
userServiceInstance,
transport,
transportInstance,
) = userServiceManager().getService(
request.user, request.os, request.ip, idService, idTransport, doTest=True
)
# logger.debug('Res: %s %s %s %s %s', ip, userService, userServiceInstance, transport, transportInstance)
except ServiceNotReadyError:
ip = None
except Exception as e:
ip = False
status = 'error'
# If service exists
if userServiceManager().locateUserService(user=request.user, idService=idService, create=False):
# Service exists...
try:
(
ip,
userService,
userServiceInstance,
transport,
transportInstance,
) = userServiceManager().getService(
request.user, request.os, request.ip, idService, idTransport, doTest=True
)
# logger.debug('Res: %s %s %s %s %s', ip, userService, userServiceInstance, transport, transportInstance)
except ServiceNotReadyError:
ip = None
except Exception as e:
ip = False
ready = 'ready'
if userService and userService.getProperty('accessedByClient') != '0':
ready = 'accessed'
ready = 'ready'
if userService and userService.getProperty('accessedByClient') != '0':
ready = 'accessed'
status = 'running' if ip is None else 'error' if ip is False else ready
status = 'running' if ip is None else 'error' if ip is False else ready
return HttpResponse(json.dumps({'status': status}), content_type='application/json')