Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ogc api processes subscriber #1313

Merged

Conversation

totycro
Copy link
Contributor

@totycro totycro commented Jul 5, 2023

Overview

Add support for OGC API Processes Subscriber

The subscription URLs are passed to the manager, which
then has to call them appropriately.

By default, managers have the attribute supports_subscribing
set to False in order to not break the API for these. The
subscriptions are only passed to if this is set to True

Related Issue / Discussion

#1285

Additional Information

Contributions and Licensing

(as per https://github.com/geopython/pygeoapi/blob/master/CONTRIBUTING.md#contributions-and-licensing)

  • I'd like to contribute [feature X|bugfix Y|docs|something else] to pygeoapi. I confirm that my contributions to pygeoapi will be compatible with the pygeoapi license guidelines at the time of contribution.
  • I have already previously agreed to the pygeoapi Contributions and Licensing Guidelines

Copy link
Member

@ricardogsilva ricardogsilva left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a core committer, so take these with a grain of salt while you wait for a review from maintainers 😄

Nice work adding this missing functionality, I just wish we could make it a bit more generic and enforce its support for all managers.

pygeoapi/util.py Outdated Show resolved Hide resolved
pygeoapi/util.py Outdated Show resolved Hide resolved
@@ -571,6 +571,17 @@ class JobStatus(Enum):
dismissed = 'dismissed'


@dataclass(frozen=True)
class Subscriber:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While I do like the idea of using a dataclass, it seems a bit inconsistent that this introduces a difference on how the various parts of an execute request are parsed, as the main execution inputs are not parsed into a typed data structure.

Ideally we would parse the full request into a typed instance (using pydantic ❤️ ) and pass that to the inner code base.

This is not to say I am against this change (quite the contrary), just food for thought for @tomkralidis 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I pretty much agree, I prefer a more explicit style here.

@@ -168,6 +168,7 @@
'http://www.opengis.net/spec/ogcapi-processes-1/1.0/conf/core',
'http://www.opengis.net/spec/ogcapi-processes-1/1.0/conf/json',
'http://www.opengis.net/spec/ogcapi-processes-1/1.0/conf/oas30'
'http://www.opengis.net/spec/ogcapi-processes-1/1.0/conf/callback',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that you introduce the subscriber functionality as an optional property of the manager, then I think we cannot assume it by default.

We would need to add this at runtime, by checking if the manager supports it.

What if we simply assume that subscriber is to be always supported? (More on this below)

@@ -232,6 +239,11 @@ def _execute_handler_sync(self, p: BaseProcessor, job_id: str,
}

self.add_job(job_metadata)
if subscriber and subscriber.inProgressUri:
response = requests.post(subscriber.inProgressUri, json={})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given my comment above about assuming pygeoapi would want to always support the subscriber feature, how about putting subscribe-related code into a method of the BaseManager class? - this method could then be reused by managers, lowering the cost of supporting this.

pygeoapi/process/manager/base.py Show resolved Hide resolved
pygeoapi/process/manager/base.py Show resolved Hide resolved
@totycro
Copy link
Contributor Author

totycro commented Jul 6, 2023

@ricardogsilva Thanks a lot for the quick feedback!

About the question whether subscriber support should be mandatory in the manager:

My reasoning was that currently existing managers wouldn't support it, but I'm not sure how many of those are really out there.

I'm currently maintaining the Kubernetes Job Manager here, which passes the execution to a Kubernetes job. So the manager itself doesn't really know when the job finishes and can't easily send success/failed notifications. I'm going to try to get this to work somehow, but in other cases maintainers might not want to add support for this.

However if there are no such managers out there, we can simply make it mandatory and remove the supports_subscribing logic.

An exception is raised in case of error, so it can't ever return None
The subscription URLs are passed to the manager, which
then has to call them appropriately.

By default, managers have the attribute `supports_subscribing`
set to `False` in order to not break the API for these. The
subscriptions are only passed to if this is set to `True`
It's mandatory in the standard.

Thx @ricardogsilva !
This increases reusability by other managers

Thanks @ricardogsilva !
@tomkralidis tomkralidis merged commit 94ae782 into geopython:master Mar 11, 2024
4 checks passed
@tomkralidis tomkralidis deleted the 1285-ogc-api-processes-subscriber branch March 11, 2024 11:16
tomkralidis added a commit to totycro/pygeoapi that referenced this pull request Mar 17, 2024
tomkralidis added a commit to totycro/pygeoapi that referenced this pull request Mar 17, 2024
)
_process.start()
return 'application/json', None, JobStatus.accepted

def _execute_handler_sync(self, p: BaseProcessor, job_id: str,
data_dict: dict) -> Tuple[str, Any, JobStatus]:
data_dict: dict,
subscriber: Optional[Subscriber] = None,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No docstring for subscriber parameter.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have the permissions to push the repo directly and not sure if this warrants a PR, would you mind adding something like this line to the sync and async execute methods?
:param subscriber: optional `Subscriber` specifying callback URLs

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll push a fix.

tomkralidis pushed a commit to totycro/pygeoapi that referenced this pull request Mar 26, 2024
* Exclude None from `get_processor` return type annotation

An exception is raised in case of error, so it can't ever return None

* Add support for OGC API Processes Subscriber

The subscription URLs are passed to the manager, which
then has to call them appropriately.

By default, managers have the attribute `supports_subscribing`
set to `False` in order to not break the API for these. The
subscriptions are only passed to if this is set to `True`

* Add ogc api callback class to conformance

https://docs.ogc.org/is/18-062r2/18-062r2.html#toc67

* Make successUri mandatory in subscriber

It's mandatory in the standard.

Thx @ricardogsilva !

* Use snake case in python for fields which are camel case in the api

Thx @ricardogsilva !

* Add subscriber to method docstring

* Provide default value for subscriber for managers not supporting it

Thanks @ricardogsilva !

* Factor out notification call into methods

This increases reusability by other managers

Thanks @ricardogsilva !

* Add an example call for a process subscriber

* Change test urls to valid urls

* Third party imports in own block
tomkralidis added a commit that referenced this pull request Apr 5, 2024
* Move api to subdirectory

* Move processes api to own file

* Adapt processes view methods

* Move openapi definition to processes api

* Use processes api in flask

* Linter

* Fix import issues

* Allow calling refactored views from starlette

* Allow calling refactored views from django

* Linter

* Move edr api to own file

* Adapt edr api to new style

* Fix typo in django views

* Move maps api to own file

* Adapt maps api to new style

* Move edr openapi to edr api file

* Move maps openapi to maps api file

* Move stac views to own file

* Refactor stac views to new file

* Move stac openapi to stac api file

* Move tiles api to own file

* Adapt tiles api to new style

* Also move tilematrixset to tiles api

* Adapt tilesetmatrix views to new style

NOTE: I had to remove one tilematrixsets test because
it tested that an invalid format would produce an error.
This now happens by default for all views, but the actual
code is outside of the endpoint function.

* update features, records, coverages

* update release version

* switch back to dev

* backport of #1313

* backport of #1313 fix

* backport of #1585

* Flask: sanitize OGC schema pathing (#1593)

* update release version

* switch back to dev

* backport of #1596

* Port test_gzip_csv test

Note that apply_gzip is now called by the web framework adapters,
so to test it in general, we have to call it in the test manually

* Add empty conformance class list to stac api

* Fix queryables call in starlette

* fix ref

* Unify request validity checking

The default case is handled by the web framework adapters. If custom
format handling is required, the check in the adapter must be skipped.

* Fix imports in django views

* backport #1598

* Remove test about format handling in endpoint

This is now handled outside of the endpoint function

* add docstring to base process manager (#1603)

* backport of #1601

* Port api ogr tests to new style

* Move processes tests to own file

* Run api tests from new dir in CI

* Move edr tests to own file

* Move maps tests to own file

* Move tiles tests to own file

* Actually hide hidden layers in openapi

* 1600 allow providing default value in config (#1604)

* move coverages tests to own file

* move itemtypes to own file, move core into init test

* fix OpenAPI output

* update tests

* add missing descriptions to OpenAPI admin responses

* update tests

* fix tests autodiscovery

* remove unused logging in tests

* address PR comments

* test with xarray 2024.2.0

* remove unneeded file

* safeguard xarray error

* unpin xarray

* fix OpenAPI generation

* fix schema endpoint in Flask and Starlette

* Safely serialize configuration JSON (#1605)

* Safely serialize configuration JSON

Co-Authored-By: Tom Kralidis <tomkralidis@gmail.com>

* Revert "Safely serialize configuration JSON"

This reverts commit 36feb06.

* Add test for datetime with Admin API

* Safely serialize configuration JSON

---------

Co-authored-by: Tom Kralidis <tomkralidis@gmail.com>

* backport #1611

* Also fix schema endpoint for django

Fix is analogous to e72d4ba

* address additional PR comments

---------

Co-authored-by: Tom Kralidis <tomkralidis@gmail.com>
Co-authored-by: Angelos Tzotsos <gcpp.kalxas@gmail.com>
Co-authored-by: Ricardo Garcia Silva <ricardo.garcia.silva@gmail.com>
Co-authored-by: Benjamin Webb <40066515+webb-ben@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants