Skip to content

Commit

Permalink
Implementing SQLalchemy for logging mechanism
Browse files Browse the repository at this point in the history
  • Loading branch information
jachym committed Aug 27, 2016
1 parent e7fc27f commit 5f579d4
Show file tree
Hide file tree
Showing 10 changed files with 152 additions and 248 deletions.
27 changes: 16 additions & 11 deletions docs/configuration.rst
Expand Up @@ -16,6 +16,7 @@ The configuration file has 3 sections:

* `metadata:main` for the server metadata inputs
* `server` for server configuration
* `loggging` for logging configuration
* `grass` for *optional* configuration to support `GRASS GIS
<http://grass.osgeo.org>`_

Expand Down Expand Up @@ -98,13 +99,6 @@ configuration file <http://docs.pycsw.org/en/latest/configuration.html>`_.
https://docs.python.org/2/library/codecs.html#standard-encodings). Default
value is 'UTF-8'

:loglevel:
the logging level (see
http://docs.python.org/library/logging.html#logging-levels)

:logfile:
the full file path to the log file

:parallelprocesses:
maximum number of parallel running processes - set this number carefully.
The effective number of parallel running processes is limited by the number
Expand All @@ -113,10 +107,6 @@ configuration file <http://docs.pycsw.org/en/latest/configuration.html>`_.
reasonable number of parallel running processes is not higher than the
number of processor cores.

:logdatabase:
SQLite3 file, where the login about requests/responses is to be stored. It
can be set to `":memory:"` to store the database in memory.

:maxrequestsize:
maximal request size. 0 for no limit

Expand All @@ -138,6 +128,21 @@ configuration file <http://docs.pycsw.org/en/latest/configuration.html>`_.
Example: `outputpath=/var/www/wps/outputs` shall correspond with
`outputurl=http://foo.bar/wps/outputs`

[logging]
---------

:level:
the logging level (see
http://docs.python.org/library/logging.html#logging-levels)

:file:
the full file path to the log file for being able to see possible error
messages.

:database:
Connection string to database where the login about requests/responses is to be stored. We are using `SQLAlchemy <http://docs.sqlalchemy.org/en/latest/core/engines.html#database-urls>`_
please use the configuration string. The default is SQLite3 `:memory:` object.


[grass]
-------
Expand Down
16 changes: 8 additions & 8 deletions pywps/app/Process.py
Expand Up @@ -189,15 +189,15 @@ def _execute_process(self, async, wps_request, wps_response):
:return: wps_response or None
"""

maxparalel = int(config.get_config_value('server', 'parallelprocesses'))
running = len(dblog.get_running())
stored = len(dblog.get_stored())
maxparallel = int(config.get_config_value('server', 'parallelprocesses'))
running = dblog.get_running().count()
stored = dblog.get_stored().count()

# async
if async:

# run immedietly
if running < maxparalel:
if running < maxparallel or maxparallel == -1:
self._run_async(wps_request, wps_response)

# try to store for later usage
Expand All @@ -207,7 +207,7 @@ def _execute_process(self, async, wps_request, wps_response):

# not async
else:
if running < maxparalel:
if running < maxparallel or maxparallel == -1:
wps_response = self._run_process(wps_request, wps_response)
else:
raise ServerBusy('Maximum number of parallel running processes reached. Please try later.')
Expand Down Expand Up @@ -275,9 +275,9 @@ def _run_process(self, wps_request, wps_response):
wps_response.update_status(msg, -1)

# tr
stored_requests = dblog.get_first_stored()
if len(stored_requests) > 0:
(uuid, request_json) = stored_requests[0]
stored_request = dblog.get_first_stored()
if stored_request:
(uuid, request_json) = (stored_request.uuid, stored_request.request)
new_wps_request = WPSRequest()
new_wps_request.json = json.loads(request_json)
new_wps_response = WPSResponse(self, new_wps_request, uuid)
Expand Down
11 changes: 7 additions & 4 deletions pywps/app/Service.py
Expand Up @@ -38,10 +38,10 @@ def __init__(self, processes=[], cfgfiles=None):
if cfgfiles:
config.load_configuration(cfgfiles)

if config.get_config_value('server', 'logfile') and config.get_config_value('server', 'loglevel'):
LOGGER.setLevel(getattr(logging, config.get_config_value('server', 'loglevel')))
if config.get_config_value('server', 'file') and config.get_config_value('logging', 'level'):
LOGGER.setLevel(getattr(logging, config.get_config_value('logging', 'level')))
msg_fmt = '%(asctime)s] [%(levelname)s] file=%(pathname)s line=%(lineno)s module=%(module)s function=%(funcName)s %(message)s'
fh = logging.FileHandler(config.get_config_value('server', 'logfile'))
fh = logging.FileHandler(config.get_config_value('server', 'file'))
fh.setFormatter(logging.Formatter(msg_fmt))
LOGGER.addHandler(fh)
else: # NullHandler
Expand Down Expand Up @@ -600,7 +600,10 @@ class FakeResponse:
message = e.locator
status = e.code
status_percentage = 100
update_response(request_uuid, FakeResponse, close=True)
try:
update_response(request_uuid, FakeResponse, close=True)
except NoApplicableCode as e:
return e
return e


Expand Down
4 changes: 2 additions & 2 deletions pywps/app/WPSResponse.py
Expand Up @@ -10,10 +10,10 @@
from pywps.dblog import update_response
from collections import namedtuple

_STATUS = namedtuple('Status', 'NO_STATUS, STORE_STATUS,'
_STATUS = namedtuple('Status', 'ERROR_STATUS, NO_STATUS, STORE_STATUS,'
'STORE_AND_UPDATE_STATUS, DONE_STATUS')

STATUS = _STATUS(0, 1, 2, 3)
STATUS = _STATUS(0, 10, 20, 30, 40)

class WPSResponse(object):

Expand Down
9 changes: 6 additions & 3 deletions pywps/configuration.py
Expand Up @@ -100,12 +100,15 @@ def load_configuration(cfgfiles=None):
outputpath = tempfile.gettempdir()
CONFIG.set('server', 'outputurl', 'file:///%s' % outputpath)
CONFIG.set('server', 'outputpath', outputpath)
CONFIG.set('server', 'logfile', '')
CONFIG.set('server', 'logdatabase', ':memory:')
CONFIG.set('server', 'loglevel', 'INFO')
CONFIG.set('server', 'workdir', tempfile.gettempdir())
CONFIG.set('server', 'parallelprocesses', '2')

CONFIG.add_section('logging')
CONFIG.set('logging', 'file', '')
CONFIG.set('logging', 'level', 'DEBUG')
CONFIG.set('logging', 'database', 'sqlite:///:memory:')
CONFIG.set('logging', 'prefix', 'pywps_')

CONFIG.add_section('metadata:main')
CONFIG.set('metadata:main', 'identification_title', 'PyWPS Processing Service')
CONFIG.set('metadata:main', 'identification_abstract', 'PyWPS is an implementation of the Web Processing Service standard from the Open Geospatial Consortium. PyWPS is written in Python.')
Expand Down

0 comments on commit 5f579d4

Please sign in to comment.