Skip to content

Commit

Permalink
Implement sub-path for status request
Browse files Browse the repository at this point in the history
  • Loading branch information
gschwind committed Feb 7, 2024
1 parent c67cd9d commit de7cc67
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 36 deletions.
2 changes: 1 addition & 1 deletion pywps/app/Process.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ def status_filename(self):
@property
def status_url(self):
base_url = config.get_config_value('server', 'url')
return f"{base_url}?service=WPS&request=status&uuid={self.uuid}"
return f"{base_url}/status?uuid={self.uuid}"

def _execute_process(self, async_, wps_request, wps_response):
"""
Expand Down
73 changes: 40 additions & 33 deletions pywps/app/Service.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,15 @@ def __init__(self, processes: Sequence = [], cfgfiles=None, preprocessors: Optio
if not LOGGER.handlers:
LOGGER.addHandler(logging.NullHandler())

def get_status(self, wps_request, uuid):
def get_status(self, http_request):
try:
_, mimetype = get_response_type(wps_request.http_request.accept_mimetypes,
wps_request.default_mimetype)
_, mimetype = get_response_type(http_request.accept_mimetypes,
"text/xml")
except Exception:
mimetype = get_default_response_mimetype()
return StatusResponse(wps_request.version, wps_request.requested_status_uuid, mimetype)
from urllib.parse import parse_qs
request = parse_qs(http_request.environ["QUERY_STRING"])
return StatusResponse(request.get("version", ["1.0.0"])[0], request["uuid"][0], mimetype)

def get_capabilities(self, wps_request, uuid):
return CapabilitiesResponse(wps_request, uuid, version=wps_request.version, processes=self.processes)
Expand Down Expand Up @@ -168,39 +170,44 @@ def call(self, http_request):
LOGGER.debug('Setting PYWPS_CFG to {}'.format(environ_cfg))
os.environ['PYWPS_CFG'] = environ_cfg

wps_request = WPSRequest(http_request, self.preprocessors)
LOGGER.info('Request: {}'.format(wps_request.operation))
if wps_request.operation in ['getcapabilities',
'describeprocess',
'execute',
'status']:
log_request(request_uuid, wps_request)
if http_request.environ["PATH_INFO"] == "/status":
try:
response = None
if wps_request.operation == 'getcapabilities':
response = self.get_capabilities(wps_request, request_uuid)
response._update_status(WPS_STATUS.SUCCEEDED, '', 100)

elif wps_request.operation == 'describeprocess':
response = self.describe(wps_request, request_uuid, wps_request.identifiers)
response._update_status(WPS_STATUS.SUCCEEDED, '', 100)

elif wps_request.operation == 'execute':
response = self.execute(
wps_request.identifier,
wps_request,
request_uuid
)
elif wps_request.operation == 'status':
response = self.get_status(wps_request, request_uuid)
return response
return self.get_status(http_request)
except Exception as e:
# This ensure that logged request get terminated in case of exception while the request is not
# accepted
store_status(request_uuid, WPS_STATUS.FAILED, 'Request rejected due to exception', 100)
store_status(request_uuid, WPS_STATUS.FAILED,
'Request rejected due to exception', 100)
raise e
else:
raise RuntimeError("Unknown operation {}".format(wps_request.operation))
wps_request = WPSRequest(http_request, self.preprocessors)
LOGGER.info('Request: {}'.format(wps_request.operation))
if wps_request.operation in ['getcapabilities',
'describeprocess',
'execute']:
log_request(request_uuid, wps_request)
try:
response = None
if wps_request.operation == 'getcapabilities':
response = self.get_capabilities(wps_request, request_uuid)
response._update_status(WPS_STATUS.SUCCEEDED, '', 100)

elif wps_request.operation == 'describeprocess':
response = self.describe(wps_request, request_uuid, wps_request.identifiers)
response._update_status(WPS_STATUS.SUCCEEDED, '', 100)

elif wps_request.operation == 'execute':
response = self.execute(
wps_request.identifier,
wps_request,
request_uuid
)
return response
except Exception as e:
# This ensure that logged request get terminated in case of exception while the request is not
# accepted
store_status(request_uuid, WPS_STATUS.FAILED, 'Request rejected due to exception', 100)
raise e
else:
raise RuntimeError("Unknown operation {}".format(wps_request.operation))

except NoApplicableCode as e:
return e
Expand Down
2 changes: 1 addition & 1 deletion tests/test_assync.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def test_async(self):
total_time = 0
sleep_time = .01
while wps.status not in ["ProcessSucceeded", "ProcessFailed"]:
resp = client.get(f'{url.path}?{url.query}').data
resp = client.open(base_url='/wps', path='/status', method='GET', query_string=url.query).data
if resp:
wps.checkStatus(response=resp, sleepSecs=0.01)
else:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_wps_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,6 @@ def test_wps_status(self):

# Parse url because we do not have real server
url = urlparse(url)
resp = client.get(f'{url.path}?{url.query}')
resp = client.open(base_url='/wps', path='/status', method='GET', query_string=url.query)
assert_response_success(resp)

0 comments on commit de7cc67

Please sign in to comment.