Skip to content

Usage of Interface

Job interface

Todo...

Dispatcher

The dispatcher (qgis_server_light.dispatcher, installed with the extra dispatcher, see Dev the project) is what your 3rd party application uses to put jobs into the redis queue and to get their results back. There are two of them, one for each way a worker delivers the result. Each one needs workers booted with the matching engine (see CLI).

Jobs you wait for

RedisQueue is meant for the short living map related jobs (render, feature info, legend, feature, crs). post queues the job, waits maximum to seconds for the result and returns it together with the status. The worker publishes the result to the dispatcher, nothing is kept in redis afterwards. It needs workers with the publish engine.

from qgis_server_light.dispatcher.redis_asio import RedisQueue

queue = RedisQueue.create("redis://redis:6379")
job_result, status = await queue.post(job_parameter, to=10.0)

Jobs which keep their state

RedisStateQueue is meant for processes, which may run for a long time. submit queues the job and returns right away. The job id is given by you, so you can refer to the job later. The worker keeps the status and the result in the job hash, which expires 24 hours after submit and again 24 hours after the job finished. Until then:

  • state reads the current state of the job (JobState: status, last update, result or error message and the progress in percent, if the algorithm reports one). It returns None if the job does not exist (anymore).
  • wait waits maximum to seconds for the job to finish and returns its state. This is how a synchronous execution is done. The worker only notifies a waiting dispatcher if the job was submitted with ExecutionMode.SYNC, otherwise wait always runs into the timeout.
  • dismiss stops the job and returns its state. A queued job is taken off the queue and is dismissed right away. A running job gets a cancel flag in its job hash, its worker cancels the QGIS algorithm and finishes the job as dismissed a moment later (see CLI). A finished job stays as it is, None is returned if the job does not exist (anymore).
  • process_descriptions reads the descriptions of the processes the alive process workers serve and merges them into one list. Workers on one redis should run the same QGIS and serve the same processes. If they don't, the description of the newest QGIS is taken and the process gets a ProcessWarning, so the deployment can be corrected.

It needs workers with the state engine.

from qgis_server_light.dispatcher.redis_asio import RedisStateQueue
from qgis_server_light.interface.job.common.input import ExecutionMode

queue = RedisStateQueue.create("redis://redis:6379")
await queue.submit(job_id, job_parameter, ExecutionMode.SYNC)
job_state = await queue.wait(job_id, to=30.0)

The result of a succeeded process is a ProcessResult (the outputs and the log of the QGIS algorithm) as JSON in job_state.result.data. It is parsed back with xsdata:

from xsdata.formats.dataclass.parsers import JsonParser

from qgis_server_light.interface.job.process.output import ProcessResult

process_result = JsonParser().from_bytes(job_state.result.data, ProcessResult)

The value of an output is either a literal (e.g. a number or a string) or a Reference. A Reference holds the path of the file relative to the process output dir of the worker ({job_id}/{output_name}.{extension}) and its media type. To read the file, your application needs access to the same dir (see CLI).

The shape of processes

The descriptions, the execute request and the result are shaped along OGC API - Processes - Part 1: Core (qgis_server_light.interface.job.process), so an application can expose them without much translation. Two things differ:

  • The inputs and outputs are lists of entries carrying their id, OGC API - Processes holds them as maps by id. xsdata can't bind a map of dataclasses.
  • An input whose value is a layer is marked in its schema with x-qsl-layer (QslLayerMarker): the kinds of layer it accepts (vector, raster) and the geometry types of a vector layer. QGIS-Server-Light doesn't know which layers exist, the application replaces the marker with the layers it offers and sends the chosen one as QslJobLayer in the execute request.

The values of an input are always a list, one entry for an input taking a single value. A file output is written in the first format its description offers, unless the execute request chooses another one.