Skip to content

Async job execution #8

@danlooo

Description

@danlooo

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"
}%

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions