mirror of
https://github.com/EDCD/EDMarketConnector.git
synced 2025-06-09 11:52:27 +03:00
CAPI: Use special EDMCCAPIRequest endpoint, not 'None' for worker shutdown
This commit is contained in:
parent
503658bf4e
commit
40a8a19ce4
22
companion.py
22
companion.py
@ -537,6 +537,8 @@ class EDMCCAPIReturn:
|
|||||||
class EDMCCAPIRequest(EDMCCAPIReturn):
|
class EDMCCAPIRequest(EDMCCAPIReturn):
|
||||||
"""Encapsulates a request for CAPI data."""
|
"""Encapsulates a request for CAPI data."""
|
||||||
|
|
||||||
|
REQUEST_WORKER_SHUTDOWN = '__EDMC_WORKER_SHUTDOWN'
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self, endpoint: str, query_time: int,
|
self, endpoint: str, query_time: int,
|
||||||
tk_response_event: Optional[str] = None, retrying: bool = False,
|
tk_response_event: Optional[str] = None, retrying: bool = False,
|
||||||
@ -597,7 +599,7 @@ class Session(object):
|
|||||||
self.capi_raw_data = CAPIDataRaw() # Cache of raw replies from CAPI service
|
self.capi_raw_data = CAPIDataRaw() # Cache of raw replies from CAPI service
|
||||||
# Queue that holds requests for CAPI queries, the items should always
|
# Queue that holds requests for CAPI queries, the items should always
|
||||||
# be EDMCCAPIRequest objects.
|
# be EDMCCAPIRequest objects.
|
||||||
self.capi_query_queue: Queue[Optional[EDMCCAPIRequest]] = Queue()
|
self.capi_request_queue: Queue[EDMCCAPIRequest] = Queue()
|
||||||
# This queue is used to pass the result, possibly a failure, of CAPI
|
# This queue is used to pass the result, possibly a failure, of CAPI
|
||||||
# queries back to the requesting code (technically anything checking
|
# queries back to the requesting code (technically anything checking
|
||||||
# this queue, but it should be either EDMarketConnector.AppWindow or
|
# this queue, but it should be either EDMarketConnector.AppWindow or
|
||||||
@ -876,14 +878,13 @@ class Session(object):
|
|||||||
return station_data
|
return station_data
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
query = self.capi_query_queue.get()
|
query = self.capi_request_queue.get()
|
||||||
if not isinstance(query, EDMCCAPIRequest):
|
if not isinstance(query, EDMCCAPIRequest):
|
||||||
if query is not None:
|
|
||||||
logger.error("Item from queue wasn't an EDMCCAPIRequest")
|
logger.error("Item from queue wasn't an EDMCCAPIRequest")
|
||||||
break
|
break
|
||||||
|
|
||||||
else:
|
if query.endpoint == query.REQUEST_WORKER_SHUTDOWN:
|
||||||
logger.info('Empty queue message, exiting...')
|
logger.info(f'endpoint {query.REQUEST_WORKER_SHUTDOWN}, exiting...')
|
||||||
break
|
break
|
||||||
|
|
||||||
logger.trace_if('capi.worker', f'Processing query: {query.endpoint}')
|
logger.trace_if('capi.worker', f'Processing query: {query.endpoint}')
|
||||||
@ -949,7 +950,12 @@ class Session(object):
|
|||||||
|
|
||||||
def capi_query_close_worker(self) -> None:
|
def capi_query_close_worker(self) -> None:
|
||||||
"""Ask the CAPI query thread to finish."""
|
"""Ask the CAPI query thread to finish."""
|
||||||
self.capi_query_queue.put(None)
|
self.capi_request_queue.put(
|
||||||
|
EDMCCAPIRequest(
|
||||||
|
endpoint=EDMCCAPIRequest.REQUEST_WORKER_SHUTDOWN,
|
||||||
|
query_time=int(time.time())
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
def query(
|
def query(
|
||||||
self, endpoint: str, query_time: int,
|
self, endpoint: str, query_time: int,
|
||||||
@ -983,7 +989,7 @@ class Session(object):
|
|||||||
if conf_module.capi_pretend_down:
|
if conf_module.capi_pretend_down:
|
||||||
raise ServerConnectionError(f'Pretending CAPI down: {endpoint}')
|
raise ServerConnectionError(f'Pretending CAPI down: {endpoint}')
|
||||||
|
|
||||||
self.capi_query_queue.put(
|
self.capi_request_queue.put(
|
||||||
EDMCCAPIRequest(
|
EDMCCAPIRequest(
|
||||||
endpoint=endpoint,
|
endpoint=endpoint,
|
||||||
tk_response_event=tk_response_event,
|
tk_response_event=tk_response_event,
|
||||||
@ -1032,7 +1038,7 @@ class Session(object):
|
|||||||
:param auto_update: Whether this request was triggered automatically.
|
:param auto_update: Whether this request was triggered automatically.
|
||||||
"""
|
"""
|
||||||
# Ask the thread worker to perform all three queries
|
# Ask the thread worker to perform all three queries
|
||||||
self.capi_query_queue.put(
|
self.capi_request_queue.put(
|
||||||
EDMCCAPIRequest(
|
EDMCCAPIRequest(
|
||||||
endpoint=self._CAPI_PATH_STATION,
|
endpoint=self._CAPI_PATH_STATION,
|
||||||
tk_response_event=tk_response_event,
|
tk_response_event=tk_response_event,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user