def _execute_process(self, async_, wps_request, wps_response): """Uses :module:`pywps.processing` module for sending process to background BUT first, check for maxprocesses configuration value :param async_: run in asynchronous mode :return: wps_response or None """ maxparallel = int(config.get_config_value('server', 'parallelprocesses')) running, stored = dblog.get_process_counts() # async if async_: # run immedietly LOGGER.debug("Running processes: {} of {} allowed parallelprocesses".format(running, maxparallel)) LOGGER.debug("Stored processes: {}".format(stored)) maxprocesses = int(config.get_config_value('server', 'maxprocesses')) if stored >= maxprocesses: raise ServerBusy('Maximum number of processes in queue reached. Please try later.') LOGGER.debug("Store process in job queue, uuid={}".format(self.uuid)) dblog.store_request(self.uuid, wps_request, self) wps_response._update_status(WPS_STATUS.ACCEPTED, 'PyWPS Process stored in job queue', 0) # not async else: if running >= maxparallel and maxparallel != -1: raise ServerBusy('Maximum number of parallel running processes reached. Please try later.') wps_response._update_status(WPS_STATUS.ACCEPTED, "PyWPS Request accepted", 0) wps_response = self.run_process(wps_request, wps_response) return wps_response
def run(self): old_running = old_stored = 0 while True: # Logging errors and exceptions try: running, stored = dblog.get_process_counts() if old_running != running or old_stored != stored: old_running = running old_stored = stored LOGGER.info( 'PyWPS job queue: {} running processes {} stored requests' .format(running, stored)) while (running < self.maxparallel or self.maxparallel == -1) and stored > 0: launch_process() running, stored = dblog.get_process_counts() except Exception as e: LOGGER.exception("PyWPS job queue failed: {}".format(str(e))) # The job queue will repeat your tasks according to this variable # it's in second so 60 is 1 minute, 3600 is 1 hour, etc. time.sleep(self.max_time)
def _execute_process(self, async_, wps_request, wps_response): """Uses :module:`pywps.processing` module for sending process to background BUT first, check for maxprocesses configuration value :param async_: run in asynchronous mode :return: wps_response or None """ maxparallel = int(config.get_config_value('server', 'parallelprocesses')) running, stored = dblog.get_process_counts() # async if async_: # run immedietly LOGGER.debug("Running processes: {} of {} allowed parallelprocesses".format(running, maxparallel)) LOGGER.debug("Stored processes: {}".format(stored)) if running < maxparallel or maxparallel == -1: wps_response._update_status(WPS_STATUS.ACCEPTED, u"PyWPS Request accepted", 0) LOGGER.debug("Accepted request {}".format(self.uuid)) self._run_async(wps_request, wps_response) # try to store for later usage else: maxprocesses = int(config.get_config_value('server', 'maxprocesses')) if stored >= maxprocesses: raise ServerBusy('Maximum number of processes in queue reached. Please try later.') LOGGER.debug("Store process in job queue, uuid={}".format(self.uuid)) dblog.store_process(self.uuid, wps_request) wps_response._update_status(WPS_STATUS.ACCEPTED, u'PyWPS Process stored in job queue', 0) # not async else: if running >= maxparallel and maxparallel != -1: raise ServerBusy('Maximum number of parallel running processes reached. Please try later.') wps_response._update_status(WPS_STATUS.ACCEPTED, u"PyWPS Request accepted", 0) wps_response = self._run_process(wps_request, wps_response) return wps_response
class Process(object): """ :param handler: A callable that gets invoked for each incoming request. It should accept a single :class:`pywps.app.WPSRequest` argument and return a :class:`pywps.app.WPSResponse` object. :param string identifier: Name of this process. :param string title: Human readable title of process. :param string abstract: Brief narrative description of the process. :param list keywords: Keywords that characterize a process. :param inputs: List of inputs accepted by this process. They should be :class:`~LiteralInput` and :class:`~ComplexInput` and :class:`~BoundingBoxInput` objects. :param outputs: List of outputs returned by this process. They should be :class:`~LiteralOutput` and :class:`~ComplexOutput` and :class:`~BoundingBoxOutput` objects. :param metadata: List of metadata advertised by this process. They should be :class:`pywps.app.Common.Metadata` objects. """ def __init__(self, handler, identifier, title, abstract='', keywords=[], profile=[], metadata=[], inputs=[], outputs=[], version='None', store_supported=False, status_supported=False, grass_location=None): self.identifier = identifier self.handler = handler self.title = title self.abstract = abstract self.keywords = keywords self.metadata = metadata self.profile = profile self.version = version self.inputs = inputs self.outputs = outputs self.uuid = None self.status_location = '' self.status_url = '' self.workdir = None self._grass_mapset = None self.grass_location = grass_location self.service = None if store_supported: self.store_supported = 'true' else: self.store_supported = 'false' if status_supported: self.status_supported = 'true' else: self.status_supported = 'false' @property def json(self): return { 'version': self.version, 'identifier': self.identifier, 'title': self.title, 'abstract': self.abstract, 'keywords': self.keywords, 'metadata': [m for m in self.metadata], 'inputs': [i.json for i in self.inputs], 'outputs': [o.json for o in self.outputs], 'store_supported': self.store_supported, 'status_supported': self.status_supported, 'profile': [p for p in self.profile], } def execute(self, wps_request, uuid): self._set_uuid(uuid) self. async = False response_cls = get_response("execute") wps_response = response_cls(wps_request, process=self, uuid=self.uuid) LOGGER.debug( 'Check if status storage and updating are supported by this process' ) if wps_request.store_execute == 'true': if self.store_supported != 'true': raise StorageNotSupported( 'Process does not support the storing of the execute response' ) if wps_request.status == 'true': if self.status_supported != 'true': raise OperationNotSupported( 'Process does not support the updating of status') wps_response.store_status_file = True self. async = True else: wps_response.store_status_file = False LOGGER.debug( 'Check if updating of status is not required then no need to spawn a process' ) wps_response = self._execute_process(self. async, wps_request, wps_response) return wps_response def _set_uuid(self, uuid): """Set uuid and status location path and url """ self.uuid = uuid for inpt in self.inputs: inpt.uuid = uuid for outpt in self.outputs: outpt.uuid = uuid file_path = config.get_config_value('server', 'outputpath') file_url = config.get_config_value('server', 'outputurl') self.status_location = os.path.join(file_path, str(self.uuid)) + '.xml' self.status_url = os.path.join(file_url, str(self.uuid)) + '.xml' def _execute_process(self, async, wps_request, wps_response): """Uses :module:`pywps.processing` module for sending process to background BUT first, check for maxprocesses configuration value :param async: run in asynchronous mode :return: wps_response or None """ maxparallel = int( config.get_config_value('server', 'parallelprocesses')) running, stored = dblog.get_process_counts() # async if async: # run immedietly LOGGER.debug( "Running processes: {} of {} allowed parallelprocesses".format( running, maxparallel)) LOGGER.debug("Stored processes: {}".format(stored)) if running < maxparallel or maxparallel == -1: wps_response._update_status(WPS_STATUS.ACCEPTED, u"PyWPS Request accepted", 0) LOGGER.debug("Accepted request {}".format(self.uuid)) self._run_async(wps_request, wps_response) # try to store for later usage else: maxprocesses = int( config.get_config_value('server', 'maxprocesses')) if stored >= maxprocesses: raise ServerBusy( 'Maximum number of processes in queue reached. Please try later.' ) LOGGER.debug("Store process in job queue, uuid={}".format( self.uuid)) dblog.store_process(self.uuid, wps_request) wps_response._update_status( WPS_STATUS.ACCEPTED, u'PyWPS Process stored in job queue', 0) # not async else: if running >= maxparallel and maxparallel != -1: raise ServerBusy( 'Maximum number of parallel running processes reached. Please try later.' ) wps_response._update_status(WPS_STATUS.ACCEPTED, u"PyWPS Request accepted", 0) wps_response = self._run_process(wps_request, wps_response) return wps_response