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

initialize processor on server boot #2059

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
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
Loading