mirror of
https://github.com/dkmstr/openuds.git
synced 2025-01-05 09:17:54 +03:00
Fixing actor issues
This commit is contained in:
parent
65d4b0b409
commit
293cb129ed
@ -72,7 +72,7 @@ class UDSClientQApp(QApplication):
|
||||
self._app.start()
|
||||
self._initialized = True
|
||||
|
||||
def end(self, sessionManager=None) -> None:
|
||||
def end(self, sessionManager=None) -> None: # pylint: disable=unused-argument
|
||||
if not self._initialized:
|
||||
return
|
||||
|
||||
@ -87,12 +87,12 @@ class UDSClientQApp(QApplication):
|
||||
QMessageBox.information(None, 'Message', message)
|
||||
|
||||
|
||||
class UDSActorClient(threading.Thread):
|
||||
class UDSActorClient(threading.Thread): # pylint: disable=too-many-instance-attributes
|
||||
_running: bool
|
||||
_forceLogoff: bool
|
||||
_qApp: UDSClientQApp
|
||||
_listener: client.HTTPServerThread
|
||||
_loginInfo: typing.Optional[types.LoginResultInfoType]
|
||||
_loginInfo: typing.Optional['types.LoginResultInfoType']
|
||||
_notified: bool
|
||||
_sessionStartTime: datetime.datetime
|
||||
api: rest.UDSClientApi
|
||||
@ -118,7 +118,7 @@ class UDSActorClient(threading.Thread):
|
||||
self.stop()
|
||||
|
||||
def checkDeadLine(self):
|
||||
if self._userInfo is None or not self._userInfo.dead_line: # No deadline check
|
||||
if self._loginInfo is None or not self._loginInfo.dead_line: # No deadline check
|
||||
return
|
||||
|
||||
remainingTime = self._loginInfo.dead_line - (datetime.datetime.now() - self._sessionStartTime).total_seconds()
|
||||
@ -135,7 +135,7 @@ class UDSActorClient(threading.Thread):
|
||||
self._forceLogoff = True
|
||||
|
||||
def checkIdle(self):
|
||||
if self._userInfo is None or not self._userInfo.max_idle: # No idle check
|
||||
if self._loginInfo is None or not self._loginInfo.max_idle: # No idle check
|
||||
return
|
||||
|
||||
idleTime = platform.operations.getIdleDuration()
|
||||
@ -147,7 +147,7 @@ class UDSActorClient(threading.Thread):
|
||||
|
||||
logger.debug('User has been idle for: {}'.format(idleTime))
|
||||
|
||||
if not self._idleNotified and remainingTime < 120: # With two minutes, show a warning message
|
||||
if not self._notified and remainingTime < 120: # With two minutes, show a warning message
|
||||
self._notified = True
|
||||
self._showMessage('You have been idle for too long. The session will end if you don\'t resume operations.')
|
||||
|
||||
|
@ -78,8 +78,10 @@ class UDSActorClientPool:
|
||||
self._post('message', {'message': message})
|
||||
|
||||
def ping(self) -> bool:
|
||||
if not self._clientUrl:
|
||||
return True # No clients, ping ok
|
||||
self._post('ping', {}, timeout=1)
|
||||
return bool(self._clientUrl) # if no clients available
|
||||
return bool(self._clientUrl) # There was clients, but they are now lost!!!
|
||||
|
||||
def screenshot(self) -> typing.Optional[str]: # Screenshot are returned as base64
|
||||
for r in self._post('screenshot', {}, timeout=3):
|
||||
|
@ -78,9 +78,9 @@ class Logger:
|
||||
return
|
||||
|
||||
msg = message % args
|
||||
# If remote logger is available, notify message to it
|
||||
# If remote logger is available, notify message to it (except DEBUG messages OFC)
|
||||
try:
|
||||
if self.remoteLogger:
|
||||
if self.remoteLogger and level <= DEBUG:
|
||||
self.remoteLogger.log(self.own_token, level, msg)
|
||||
except Exception as e:
|
||||
self.localLogger.log(DEBUG, 'Log to broker: {}'.format(e))
|
||||
|
@ -138,12 +138,15 @@ class CommonService: # pylint: disable=too-many-instance-attributes
|
||||
if srvInterface:
|
||||
# Rery while RESTConnectionError (that is, cannot connect)
|
||||
counter = 8
|
||||
logged = False
|
||||
while self._isAlive:
|
||||
counter -= 1
|
||||
try:
|
||||
self._certificate = self._api.ready(self._cfg.own_token, self._secret, srvInterface.ip, rest.LISTEN_PORT)
|
||||
except rest.RESTConnectionError as e:
|
||||
logger.info('Error connecting with UDS Broker')
|
||||
if not logged: # Only log connection problems ONCE
|
||||
logged = True
|
||||
logger.error('Error connecting with UDS Broker')
|
||||
self.doWait(5000)
|
||||
continue
|
||||
except Exception as e:
|
||||
@ -165,7 +168,7 @@ class CommonService: # pylint: disable=too-many-instance-attributes
|
||||
self._cfg = self._cfg._replace(config=self._cfg.config._replace(os=None), data=None)
|
||||
platform.store.writeConfig(self._cfg)
|
||||
|
||||
logger.debug('Done setReady')
|
||||
logger.info('Service ready')
|
||||
self._startHttpServer()
|
||||
|
||||
def configureMachine(self) -> bool:
|
||||
@ -325,14 +328,16 @@ class CommonService: # pylint: disable=too-many-instance-attributes
|
||||
self.reboot()
|
||||
|
||||
def loop(self):
|
||||
# Main common luop
|
||||
# Main common loop
|
||||
try:
|
||||
# Checks if ips has changed
|
||||
self.checkIpsChanged()
|
||||
|
||||
# Checks if ips has changed
|
||||
self.checkIpsChanged()
|
||||
|
||||
# Now check if every registered client is already there (if logged in OFC)
|
||||
if self._loggedIn and self._clientsPool.ping():
|
||||
self.logout('client_unavailable')
|
||||
# Now check if every registered client is already there (if logged in OFC)
|
||||
if self._loggedIn and not self._clientsPool.ping():
|
||||
self.logout('client_unavailable')
|
||||
except Exception as e:
|
||||
logger.error('Exception on main service loop: %s', e)
|
||||
|
||||
# ******************************************************
|
||||
# Methods that can be overriden by linux & windows Actor
|
||||
|
Loading…
Reference in New Issue
Block a user