Skip to content

Commit 591a9ef

Browse files
authored
emit jobs endpoints only when manager supports async (#2291) (#2292)
* emit jobs endpoints only when manager supports async (#2291) * update tests
1 parent ab73661 commit 591a9ef

6 files changed

Lines changed: 105 additions & 85 deletions

File tree

pygeoapi/api/__init__.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -700,11 +700,6 @@ def landing_page(api: API,
700700
'type': FORMAT_TYPES[F_JSON],
701701
'title': l10n.translate('Processes', request.locale),
702702
'href': f"{api.base_url}/processes"
703-
}, {
704-
'rel': f'{OGC_RELTYPES_BASE}/job-list',
705-
'type': FORMAT_TYPES[F_JSON],
706-
'title': l10n.translate('Jobs', request.locale),
707-
'href': f"{api.base_url}/jobs"
708703
}, {
709704
'rel': f'{OGC_RELTYPES_BASE}/tiling-schemes',
710705
'type': FORMAT_TYPES[F_JSON],
@@ -730,6 +725,20 @@ def landing_page(api: API,
730725

731726
fcm['links'].append(pubsub_link)
732727

728+
if api.manager.is_async:
729+
fcm['links'].append({
730+
'rel': f'{OGC_RELTYPES_BASE}/job-list',
731+
'type': FORMAT_TYPES[F_JSON],
732+
'title': l10n.translate('Jobs', request.locale),
733+
'href': f"{api.base_url}/jobs"
734+
})
735+
fcm['links'].append({
736+
'rel': f'{OGC_RELTYPES_BASE}/job-list',
737+
'type': FORMAT_TYPES[F_HTML],
738+
'title': l10n.translate('Jobs', request.locale),
739+
'href': f"{api.base_url}/jobs?f=html"
740+
})
741+
733742
if api.asyncapi:
734743
fcm['links'].append({
735744
'rel': 'service-doc',
@@ -760,6 +769,9 @@ def landing_page(api: API,
760769
'tile'):
761770
fcm['tile'] = True
762771

772+
if api.manager.is_async:
773+
fcm['jobs'] = True
774+
763775
if api.pubsub_client is not None and not api.pubsub_client.hidden:
764776
fcm['pubsub'] = {
765777
'name': api.pubsub_client.name,

pygeoapi/api/processes.py

Lines changed: 79 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,6 @@ def describe_processes(api: API, request: APIRequest,
142142

143143
p2['links'] = p2.get('links', [])
144144

145-
jobs_url = f"{api.base_url}/jobs"
146145
process_url = f"{api.base_url}/processes/{key}"
147146

148147
# TODO translation support
@@ -164,23 +163,22 @@ def describe_processes(api: API, request: APIRequest,
164163
}
165164
p2['links'].append(link)
166165

167-
link = {
168-
'type': FORMAT_TYPES[F_HTML],
169-
'rel': 'http://www.opengis.net/def/rel/ogc/1.0/job-list',
170-
'href': f'{jobs_url}?f={F_HTML}',
171-
'title': l10n.translate('Jobs list as HTML', request.locale), # noqa
172-
'hreflang': api.default_locale
173-
}
174-
p2['links'].append(link)
175-
176-
link = {
177-
'type': FORMAT_TYPES[F_JSON],
178-
'rel': 'http://www.opengis.net/def/rel/ogc/1.0/job-list',
179-
'href': f'{jobs_url}?f={F_JSON}',
180-
'title': l10n.translate('Jobs list as JSON', request.locale), # noqa
181-
'hreflang': api.default_locale
182-
}
183-
p2['links'].append(link)
166+
if api.manager.is_async:
167+
jobs_url = f"{api.base_url}/jobs"
168+
p2['links'].append({
169+
'type': FORMAT_TYPES[F_HTML],
170+
'rel': 'http://www.opengis.net/def/rel/ogc/1.0/job-list',
171+
'href': f'{jobs_url}?f={F_HTML}',
172+
'title': l10n.translate('Jobs list as HTML', request.locale), # noqa
173+
'hreflang': api.default_locale
174+
})
175+
p2['links'].append({
176+
'type': FORMAT_TYPES[F_JSON],
177+
'rel': 'http://www.opengis.net/def/rel/ogc/1.0/job-list',
178+
'href': f'{jobs_url}?f={F_JSON}',
179+
'title': l10n.translate('Jobs list as JSON', request.locale), # noqa
180+
'hreflang': api.default_locale
181+
})
184182

185183
link = {
186184
'type': FORMAT_TYPES[F_JSON],
@@ -825,68 +823,73 @@ def get_oas_30(cfg: dict, locale: str
825823
}
826824
}
827825

828-
paths['/jobs'] = {
829-
'get': {
830-
'summary': 'Retrieve jobs list',
831-
'description': 'Retrieve a list of jobs',
832-
'tags': ['jobs'],
833-
'operationId': 'getJobs',
834-
'responses': {
835-
'200': {'$ref': '#/components/responses/200'},
836-
'404': {'$ref': f"{OPENAPI_YAML['oapip']}/responses/NotFound.yaml"}, # noqa
837-
'default': {'$ref': '#/components/responses/default'}
826+
tag_objects = [{'name': 'processes'}]
827+
828+
if process_manager.is_async:
829+
paths['/jobs'] = {
830+
'get': {
831+
'summary': 'Retrieve jobs list',
832+
'description': 'Retrieve a list of jobs',
833+
'tags': ['jobs'],
834+
'operationId': 'getJobs',
835+
'responses': {
836+
'200': {'$ref': '#/components/responses/200'},
837+
'404': {'$ref': f"{OPENAPI_YAML['oapip']}/responses/NotFound.yaml"}, # noqa
838+
'default': {'$ref': '#/components/responses/default'}
839+
}
838840
}
839841
}
840-
}
841842

842-
paths['/jobs/{jobId}'] = {
843-
'get': {
844-
'summary': 'Retrieve job details',
845-
'description': 'Retrieve job details',
846-
'tags': ['jobs'],
847-
'parameters': [
848-
name_in_path,
849-
{'$ref': '#/components/parameters/f'}
850-
],
851-
'operationId': 'getJob',
852-
'responses': {
853-
'200': {'$ref': '#/components/responses/200'},
854-
'404': {'$ref': f"{OPENAPI_YAML['oapip']}/responses/NotFound.yaml"}, # noqa
855-
'default': {'$ref': '#/components/responses/default'}
856-
}
857-
},
858-
'delete': {
859-
'summary': 'Cancel / delete job',
860-
'description': 'Cancel / delete job',
861-
'tags': ['jobs'],
862-
'parameters': [
863-
name_in_path
864-
],
865-
'operationId': 'deleteJob',
866-
'responses': {
867-
'204': {'$ref': '#/components/responses/204'},
868-
'404': {'$ref': f"{OPENAPI_YAML['oapip']}/responses/NotFound.yaml"}, # noqa
869-
'default': {'$ref': '#/components/responses/default'}
870-
}
871-
},
872-
}
843+
paths['/jobs/{jobId}'] = {
844+
'get': {
845+
'summary': 'Retrieve job details',
846+
'description': 'Retrieve job details',
847+
'tags': ['jobs'],
848+
'parameters': [
849+
name_in_path,
850+
{'$ref': '#/components/parameters/f'}
851+
],
852+
'operationId': 'getJob',
853+
'responses': {
854+
'200': {'$ref': '#/components/responses/200'},
855+
'404': {'$ref': f"{OPENAPI_YAML['oapip']}/responses/NotFound.yaml"}, # noqa
856+
'default': {'$ref': '#/components/responses/default'}
857+
}
858+
},
859+
'delete': {
860+
'summary': 'Cancel / delete job',
861+
'description': 'Cancel / delete job',
862+
'tags': ['jobs'],
863+
'parameters': [
864+
name_in_path
865+
],
866+
'operationId': 'deleteJob',
867+
'responses': {
868+
'204': {'$ref': '#/components/responses/204'},
869+
'404': {'$ref': f"{OPENAPI_YAML['oapip']}/responses/NotFound.yaml"}, # noqa
870+
'default': {'$ref': '#/components/responses/default'}
871+
}
872+
},
873+
}
873874

874-
paths['/jobs/{jobId}/results'] = {
875-
'get': {
876-
'summary': 'Retrieve job results',
877-
'description': 'Retrieve job results',
878-
'tags': ['jobs'],
879-
'parameters': [
880-
name_in_path,
881-
{'$ref': '#/components/parameters/f'}
882-
],
883-
'operationId': 'getJobResults',
884-
'responses': {
885-
'200': {'$ref': '#/components/responses/200'},
886-
'404': {'$ref': f"{OPENAPI_YAML['oapip']}/responses/NotFound.yaml"}, # noqa
887-
'default': {'$ref': '#/components/responses/default'}
875+
paths['/jobs/{jobId}/results'] = {
876+
'get': {
877+
'summary': 'Retrieve job results',
878+
'description': 'Retrieve job results',
879+
'tags': ['jobs'],
880+
'parameters': [
881+
name_in_path,
882+
{'$ref': '#/components/parameters/f'}
883+
],
884+
'operationId': 'getJobResults',
885+
'responses': {
886+
'200': {'$ref': '#/components/responses/200'},
887+
'404': {'$ref': f"{OPENAPI_YAML['oapip']}/responses/NotFound.yaml"}, # noqa
888+
'default': {'$ref': '#/components/responses/default'}
889+
}
888890
}
889891
}
890-
}
891892

892-
return [{'name': 'processes'}, {'name': 'jobs'}], {'paths': paths}
893+
tag_objects.append({'name': 'jobs'})
894+
895+
return tag_objects, {'paths': paths}

pygeoapi/templates/landing_page.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,15 @@ <h2>{% trans %}Processes{% endtrans %}</h2>
7575
<a href="{{ config['server']['url'] }}/processes?f=html">{% trans %}View the processes in this service{% endtrans %}</a>
7676
</p>
7777
</section>
78+
{% if data['jobs'] %}
7879
<section id="jobs">
7980
<h2>{% trans %}Jobs{% endtrans %}</h2>
8081
<p>
8182
<a title="Browse jobs" href="{{config.server.url}}/jobs">{% trans %}Browse jobs{% endtrans %}</a>
8283
</p>
8384
</section>
8485
{% endif %}
86+
{% endif %}
8587
{% if data['tile'] %}
8688
<section id="tilematrixsets">
8789
<h2>{% trans %}Tile Matrix Sets{% endtrans %}</h2>

pygeoapi/templates/processes/process.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,10 @@ <h2>{% trans %}Execution modes{% endtrans %}</h2>
7373
{% if 'sync-execute' in data.jobControlOptions %}<li>{% trans %}Synchronous{% endtrans %}</li>{% endif %}
7474
{% if 'async-execute' in data.jobControlOptions %}<li>{% trans %}Asynchronous{% endtrans %}</li>{% endif %}
7575
</ul>
76+
{% if data['jobs'] %}
7677
<h2>{% trans %}Jobs{% endtrans %}</h2>
7778
<a title="Browse jobs" href="{{config.server.url}}/jobs">{% trans %}Browse jobs{% endtrans %}</a>
79+
{% endif %}
7880
<h2>{% trans %}Links{% endtrans %}</h2>
7981
<ul>
8082
{% for link in data['links'] %}

tests/api/test_api.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ def test_root(config, api_):
520520
for link in root['links'])
521521
assert any(link['href'].endswith('f=html') and link['rel'] == 'alternate'
522522
for link in root['links'])
523-
assert len(root['links']) == 12
523+
assert len(root['links']) == 13
524524
assert 'title' in root
525525
assert root['title'] == 'pygeoapi default instance'
526526
assert 'description' in root
@@ -622,6 +622,7 @@ def test_describe_collections(config, api_):
622622
collections = json.loads(response)
623623

624624
assert len(collections) == 2
625+
print(json.dumps(collections['collections']))
625626
assert len(collections['collections']) == 10
626627
assert len(collections['links']) == 3
627628

tests/api/test_pubsub.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def test_landing_page(config, openapi, asyncapi):
5454

5555
content = json.loads(response)
5656

57-
assert len(content['links']) == 15
57+
assert len(content['links']) == 16
5858

5959
for link in content['links']:
6060
if link.get('rel') == 'hub':
@@ -76,7 +76,7 @@ def test_landing_page(config, openapi, asyncapi):
7676

7777
content = json.loads(response)
7878

79-
assert len(content['links']) == 12
79+
assert len(content['links']) == 13
8080

8181
for link in content['links']:
8282
if link.get('rel') == 'hub':
@@ -96,7 +96,7 @@ def test_landing_page(config, openapi, asyncapi):
9696

9797
content = json.loads(response)
9898

99-
assert len(content['links']) == 15
99+
assert len(content['links']) == 16
100100

101101
for link in content['links']:
102102
if link.get('rel') == 'hub':

0 commit comments

Comments
 (0)