Skip to content

Commit 5d01f16

Browse files
Implement OGC API - Processes, Requirement 25, for jobControlOptions async-execute only, and no user preference (Issue #2231) (#2232)
* Implement OGC API - Processes, Requirement 25, for jobControlOptions async-execute only, and no user preference (Issue #2231) * Minor fix --------- Co-authored-by: FrancescoIngv <FrancescoIngv@users.noreply.github.com>
1 parent e20d7d1 commit 5d01f16

2 files changed

Lines changed: 30 additions & 16 deletions

File tree

pygeoapi/api/processes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
# Copyright (c) 2022 John A Stevenson and Colin Blackburn
1515
# Copyright (c) 2023 Ricardo Garcia Silva
1616
# Copyright (c) 2024 Bernhard Mallinger
17-
# Copyright (c) 2024 Francesco Martinelli
17+
# Copyright (c) 2026 Francesco Martinelli
1818
#
1919
# Permission is hereby granted, free of charge, to any person
2020
# obtaining a copy of this software and associated documentation
@@ -528,7 +528,7 @@ def execute_process(api: API, request: APIRequest,
528528
else:
529529
response2 = response
530530

531-
if execution_mode == RequestedProcessExecutionMode.respond_async:
531+
if (headers.get('Preference-Applied', '') == RequestedProcessExecutionMode.respond_async.value): # noqa
532532
LOGGER.debug('Asynchronous mode detected, returning statusInfo')
533533
response2 = {
534534
'jobID': job_id,

pygeoapi/process/manager/base.py

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#
77
# Copyright (c) 2024 Tom Kralidis
88
# (c) 2023 Ricardo Garcia Silva
9-
# (c) 2024 Francesco Martinelli
9+
# (c) 2026 Francesco Martinelli
1010
#
1111
# Permission is hereby granted, free of charge, to any person
1212
# obtaining a copy of this software and associated documentation
@@ -393,9 +393,10 @@ def execute_process(
393393
'requested_response': requested_response
394394
}
395395

396+
job_control_options = processor.metadata.get(
397+
'jobControlOptions', [])
398+
396399
if execution_mode == RequestedProcessExecutionMode.respond_async:
397-
job_control_options = processor.metadata.get(
398-
'jobControlOptions', [])
399400
# client wants async - do we support it?
400401
process_supports_async = (
401402
ProcessExecutionMode.async_execute.value in job_control_options
@@ -414,17 +415,30 @@ def execute_process(
414415
'Preference-Applied': (
415416
RequestedProcessExecutionMode.wait.value)
416417
}
417-
elif execution_mode == RequestedProcessExecutionMode.wait:
418-
# client wants sync - pygeoapi implicitly supports sync mode
419-
LOGGER.debug('Synchronous execution')
420-
handler = self._execute_handler_sync
421-
response_headers = {
422-
'Preference-Applied': RequestedProcessExecutionMode.wait.value}
423-
else: # client has no preference
424-
# according to OAPI - Processes spec we ought to respond with sync
425-
LOGGER.debug('Synchronous execution')
426-
handler = self._execute_handler_sync
427-
response_headers = None
418+
else: # client has no preference or clients wants sync
419+
# do we support sync?
420+
process_supports_sync = (
421+
ProcessExecutionMode.sync_execute.value in job_control_options
422+
)
423+
if not process_supports_sync:
424+
LOGGER.debug('Asynchronous execution')
425+
handler = self._execute_handler_async
426+
response_headers = {
427+
'Preference-Applied': (
428+
RequestedProcessExecutionMode.respond_async.value)
429+
}
430+
else:
431+
# according to OAPI - Processes spec we ought to
432+
# respond with sync
433+
LOGGER.debug('Synchronous execution')
434+
handler = self._execute_handler_sync
435+
if execution_mode == RequestedProcessExecutionMode.wait:
436+
response_headers = None
437+
else:
438+
response_headers = {
439+
'Preference-Applied': (
440+
RequestedProcessExecutionMode.wait.value)
441+
}
428442

429443
# Add Job before returning any response.
430444
current_status = JobStatus.accepted

0 commit comments

Comments
 (0)