Skip to content

Commit

Permalink
New process manager based on TinyDB to use multiprocessing.Process ra…
Browse files Browse the repository at this point in the history
…ther than dummy.
  • Loading branch information
david-i-berry committed Jan 25, 2024
1 parent 73c402d commit 002bc06
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions wis2box_api/plugins/process/manager/tinydb_mp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# =================================================================
#
# Authors: David Berry <dberry@wmo.int>
#
# Copyright (c) 2024 WMO
#
# Permission is hereby granted, free of charge, to any person
# obtaining a copy of this software and associated documentation
# files (the "Software"), to deal in the Software without
# restriction, including without limitation the rights to use,
# copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following
# conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
# OTHER DEALINGS IN THE SOFTWARE.
#
# =================================================================
import logging
import multiprocessing as mp
from typing import Any, Tuple

from pygeoapi.process.manager.tinydb import TinyDBManager

LOGGER = logging.getLogger(__name__)

class TinyDBManagerMP(TinyDBManager):
def _execute_handler_async(self, p: BaseProcessor, job_id: str,
data_dict: dict) -> Tuple[str, None, JobStatus]:
"""
Updated execution handler to execute a process in a background
process using `multiprocessing.Process`
https://docs.python.org/3/library/multiprocessing.html#multiprocessing.Process # noqa
:param p: `pygeoapi.process` object
:param job_id: job identifier
:param data_dict: `dict` of data parameters
:returns: tuple of None (i.e. initial response payload)
and JobStatus.accepted (i.e. initial job status)
"""
_process = mp.Process(
target=self._execute_handler_sync,
args=(p, job_id, data_dict)
)
_process.start()
return 'application/json', None, JobStatus.accepted

0 comments on commit 002bc06

Please sign in to comment.