Skip to content

Commit d633b3b

Browse files
authored
OAProc: return statusInfo object on async (geopython#2105) (geopython#2106)
* OAProc: return statusInfo object on async (geopython#2105) * fix ref
1 parent 219e4cc commit d633b3b

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

pygeoapi/api/processes.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,13 @@
5050

5151
from pygeoapi import l10n
5252
from pygeoapi.api import evaluate_limit
53-
from pygeoapi.util import (
54-
json_serial, render_j2_template, JobStatus, RequestedProcessExecutionMode,
55-
to_json, DATETIME_FORMAT)
5653
from pygeoapi.process.base import (
5754
JobNotFoundError, JobResultNotFoundError, ProcessorExecuteError
5855
)
5956
from pygeoapi.process.manager.base import get_manager, Subscriber
57+
from pygeoapi.util import (
58+
json_serial, render_j2_template, JobStatus, RequestedProcessExecutionMode,
59+
to_json, DATETIME_FORMAT)
6060

6161
from . import (
6262
APIRequest, API, SYSTEM_LOCALE, F_JSON, FORMAT_TYPES, F_HTML, F_JSONLD,
@@ -520,6 +520,14 @@ def execute_process(api: API, request: APIRequest,
520520
else:
521521
response2 = response
522522

523+
if execution_mode == RequestedProcessExecutionMode.respond_async:
524+
LOGGER.debug('Asynchronous mode detected, returning statusInfo')
525+
response2 = {
526+
'id': job_id,
527+
'type': 'process',
528+
'status': status.value
529+
}
530+
523531
return headers, http_status, response2
524532

525533

tests/api/test_processes.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -327,9 +327,13 @@ def test_execute_process(config, api_):
327327
rsp_headers, code, response = execute_process(api_, req, 'hello-world')
328328

329329
assert 'Location' in rsp_headers
330-
response = json.loads(response)
331-
assert isinstance(response, dict)
332330
assert code == HTTPStatus.CREATED
331+
assert isinstance(response, dict)
332+
assert 'id' in response
333+
assert 'type' in response
334+
assert 'status' in response
335+
assert response['type'] == 'process'
336+
assert response['status'] == 'accepted'
333337

334338
cleanup_jobs.add(tuple(['hello-world',
335339
rsp_headers['Location'].split('/')[-1]]))

0 commit comments

Comments
 (0)