Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed REST Connector stopping #1259

Merged
merged 1 commit into from
Dec 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions thingsboard_gateway/connectors/rest/rest_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.

import json
from asyncio import CancelledError, run_coroutine_threadsafe
from queue import Queue
from random import choice
from re import fullmatch
Expand Down Expand Up @@ -136,7 +137,7 @@ def open(self):
def __run_server(self):
self.endpoints = self.load_endpoints()

self._app = web.Application(debug=self.__config.get('debugMode', False))
self._app = web.Application(debug=self.__config.get('debugMode', False), logger=self.__log)

ssl_context = None
cert = None
Expand All @@ -162,7 +163,8 @@ def __run_server(self):

self.load_handlers()
web.run_app(self._app, host=self.__config['host'], port=self.__config['port'], handle_signals=False,
ssl_context=ssl_context, reuse_port=self.__config['port'], reuse_address=self.__config['host'])
ssl_context=ssl_context, reuse_port=self.__config['port'], reuse_address=self.__config['host'],
access_log=self.__log)

def run(self):
self._connected = True
Expand All @@ -171,10 +173,20 @@ def run(self):
self.__run_server()
except Exception as e:
self.__log.exception(e)
except CancelledError:
pass

async def stop_server(self):
await self._app.shutdown()
await self._app.cleanup()

def close(self):
self.__stopped = True
self._connected = False
loop = self._app.loop
run_coroutine_threadsafe(self.stop_server(), loop)
sleep(1)
self.__log.info('REST connector stopped.')
self.__log.reset()

def get_name(self):
Expand Down
Loading