Skip to content

Commit

Permalink
initialize processor on server boot
Browse files Browse the repository at this point in the history
  • Loading branch information
vvmruder committed Oct 28, 2024
1 parent a6c972f commit 64288b1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
19 changes: 19 additions & 0 deletions pyramid_oereb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

import logging

from pyramid.request import Request

from pyramid_oereb.core.adapter import DatabaseAdapter
from pyramid_oereb.core.config import Config
from pyramid.config import Configurator



log = logging.getLogger(__name__)
route_prefix = None
# initially instantiate database adapter for global session handling
Expand Down Expand Up @@ -34,6 +37,7 @@ def includeme(config):
Args:
config (Configurator): The pyramid apps config object
"""
from pyramid_oereb.core.processor import create_processor, Processor

global route_prefix

Expand All @@ -57,6 +61,21 @@ def includeme(config):
settings.update({
'pyramid_oereb': Config.get_config()
})
processor = None
try:
processor = create_processor()
except Exception as e:
log.error(f'Initialisation of processor failed with an error: {e}')
exit(1)

def get_processor(request: Request) -> Processor:
return processor

config.add_request_method(
get_processor,
'pyramid_oereb_processor',
reify=True
)

config.add_renderer('pyramid_oereb_extract_json', 'pyramid_oereb.core.renderer.extract.json_.Renderer')
config.add_renderer('pyramid_oereb_extract_xml', 'pyramid_oereb.core.renderer.extract.xml_.Renderer')
Expand Down
9 changes: 4 additions & 5 deletions pyramid_oereb/core/views/webservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
from pyramid_oereb import Config
from pyreproj import Reprojector

from pyramid_oereb.core.processor import create_processor
from pyramid_oereb.core.readers.address import AddressReader
from pyramid_oereb.core.renderer import Base as Renderer
from timeit import default_timer as timer
Expand Down Expand Up @@ -195,7 +194,7 @@ def _get_egrid_coord(self, params):
Config.get('srid'),
self.__parse_gnss__(gnss).wkt
)
processor = create_processor(real_estate_only=True)
processor = self._request.pyramid_oereb_processor
return processor.real_estate_reader.read(params, **{'geometry': geom_wkt})
else:
raise HTTPBadRequest('EN or GNSS must be defined.')
Expand All @@ -214,7 +213,7 @@ def _get_egrid_ident(self, params):
identdn = self._params.get('IDENTDN')
number = self._params.get('NUMBER')
if identdn and number:
processor = create_processor(real_estate_only=True)
processor = self._request.pyramid_oereb_processor
return processor.real_estate_reader.read(
params,
**{
Expand Down Expand Up @@ -251,7 +250,7 @@ def _get_egrid_address(self, params):
srid=Config.get('srid'),
wkt=addresses[0].geom.wkt
)
processor = create_processor(real_estate_only=True)
processor = self._request.pyramid_oereb_processor
return processor.real_estate_reader.read(params, **{'geometry': geometry})
else:
raise HTTPBadRequest('POSTALCODE, LOCALISATION and NUMBER must be defined.')
Expand All @@ -267,7 +266,7 @@ def get_extract_by_id(self):
log.debug("get_extract_by_id() start")
try:
params = self.__validate_extract_params__()
processor = create_processor()
processor = self._request.pyramid_oereb_processor
# read the real estate from configured source by the passed parameters
real_estate_reader = processor.real_estate_reader
if params.egrid:
Expand Down

0 comments on commit 64288b1

Please sign in to comment.