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

Async job execution #8

Open
danlooo opened this issue Dec 4, 2024 · 0 comments
Open

Async job execution #8

danlooo opened this issue Dec 4, 2024 · 0 comments

Comments

@danlooo
Copy link
Collaborator

danlooo commented Dec 4, 2024

Workflow execution may take several hours to run. Thus, we need a mechanism to start a job and to notify the user after its completion. Fortunately, pygeoapi has a job manager already. Async mode can be requested by adding an HTTP header.

  1. Execute the process in OGC API and request async mode by adding a header
  2. Header of the response will contain the job id
  3. We can request status and results using this job ID
curl -i -X POST http://localhost/processes/hello-world/execution \
    -H "Content-Type: application/json"  \
    -H "Prefer: respond-async"   \
    -d "{\"inputs\":{\"message\": \"Hello\", \"name\": \"world\"}}"

HTTP/1.1 201 CREATED
Server: gunicorn
Date: Wed, 04 Dec 2024 13:47:05 GMT
Connection: keep-alive
Content-Type: application/json
X-Powered-By: pygeoapi 0.18.0
Content-Language: en-US
Preference-Applied: respond-async
Location: /jobs/3f6a4e28-b246-11ef-8a79-0242ac1a0002
Access-Control-Allow-Origin: *
Content-Length: 4

curl http://localhost/jobs/3f6a4e28-b246-11ef-8a79-0242ac1a0002

{
    "type":"process",
    "processID":"hello-world",
    "jobID":"3f6a4e28-b246-11ef-8a79-0242ac1a0002",
    "status":"successful",
    "message":"Job complete",
    "progress":100,
    "parameters":null,
    "job_start_datetime":"2024-12-04T13:47:05.316464Z",
    "job_end_datetime":"2024-12-04T13:47:05.327997Z",
    "links":[
        {
            "href":"/jobs/3f6a4e28-b246-11ef-8a79-0242ac1a0002/results?f=html",
            "rel":"http://www.opengis.net/def/rel/ogc/1.0/results",
            "type":"text/html",
            "title":"Results of job as HTML"
        },
        {
            "href":"/jobs/3f6a4e28-b246-11ef-8a79-0242ac1a0002/results?f=json",
            "rel":"http://www.opengis.net/def/rel/ogc/1.0/results",
            "type":"application/json",
            "title":"Results of job as JSON"
        }
    ]
}% 


curl http://localhost/jobs/3f6a4e28-b246-11ef-8a79-0242ac1a0002/results\?f\=json

{
    "id": "echo",
    "value": "Hello world! Hello"
}%
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

No branches or pull requests

1 participant