-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathallow-specifying-job_id-via-request-parameter.patch
69 lines (61 loc) · 2.87 KB
/
allow-specifying-job_id-via-request-parameter.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
From e8773d72f0b276467ac847cce55bb925b9e28a22 Mon Sep 17 00:00:00 2001
From: Bernhard Mallinger <[email protected]>
Date: Wed, 12 Jul 2023 10:45:55 +0200
Subject: [PATCH] Allow specifying `job_id` via request parameter
This is somewhat unconventional with REST design and leaves it up to the
process implementation to deal with duplicates and invalid IDs, however
it can make sense in certain use cases.
An alternative design would be to encode the desired `job_id` in the url:
`POST /processes/<process_id>/jobs/<job_id>`
This would suggest full control over the `job_id` from the client side,
so I'd prefer to pass the id via POST data. This way we can treat it as
suggestion, or possibly as a template from which the server derives the
actual id.
---
pygeoapi/api/processes.py | 5 ++++-
pygeoapi/process/manager/base.py | 5 +++--
2 files changed, 7 insertions(+), 3 deletions(-)
diff --git pygeoapi/api/processes.py pygeoapi/api/processes.py
index e95d90a..f87f092 100644
--- pygeoapi/api/processes.py
+++ pygeoapi/api/processes.py
@@ -375,6 +375,7 @@ def execute_process(api: API, request: APIRequest,
data_dict = data.get('inputs', {})
LOGGER.debug(data_dict)
+ desired_job_id = data.get("job_id")
requested_outputs = data.get('outputs')
LOGGER.debug(f'outputs: {requested_outputs}')
@@ -410,7 +411,9 @@ def execute_process(api: API, request: APIRequest,
process_id, data_dict, execution_mode=execution_mode,
requested_outputs=requested_outputs,
subscriber=subscriber,
- requested_response=requested_response)
+ requested_response=requested_response,
+ desired_job_id=desired_job_id,
+ )
job_id, mime_type, outputs, status, additional_headers = result
headers.update(additional_headers or {})
diff --git pygeoapi/process/manager/base.py pygeoapi/process/manager/base.py
index f0d3148..7e1fe96 100644
--- pygeoapi/process/manager/base.py
+++ pygeoapi/process/manager/base.py
@@ -351,7 +351,8 @@ class BaseManager:
execution_mode: Optional[RequestedProcessExecutionMode] = None,
requested_outputs: Optional[dict] = None,
subscriber: Optional[Subscriber] = None,
- requested_response: Optional[RequestedResponse] = RequestedResponse.raw.value # noqa
+ requested_response: Optional[RequestedResponse] = RequestedResponse.raw.value, # noqa
+ desired_job_id: str | None = None,
) -> Tuple[str, Any, JobStatus, Optional[Dict[str, str]]]:
"""
Default process execution handler
@@ -379,7 +380,7 @@ class BaseManager:
response
"""
- job_id = str(uuid.uuid1())
+ job_id = desired_job_id or str(uuid.uuid1())
processor = self.get_processor(process_id)
processor.set_job_id(job_id)
extra_execute_handler_parameters = {
--
2.34.1