Web API: Asynchronous tasks =========================== Some web API commands can run for a long time depending on how much data they're dealing with, and hence, are executed asynchronously, meaning that, once invoked, they start the job in a background thread and return immediately. The response contains a unique identifier for the asynchronous task and information on the task's running status. This task identifier can then be used to poll the status of the task by querying the ``/tasks/`` API endpoint. If no task is given, e.g. by querying the ``/tasks`` endpoint, a list of all available tasks will be returned. A running task can be canceled with the ``cancel=true`` argument. For example: :: http://localhost:8182/tasks/3?cancel=true This request will ask the operation to cancel and return immediately. Note, however, that it may take some time for the cancellation request to complete, as the running task may be blocking on I/O or in a temporarily non-cancelable state. Polling the task repeatedly with the ``cancel=true`` parameter is not a problem, though. Finished tasks, whether they finished successfully, an error occurred, or were canceled, will be kept in memory for 10 minutes in order to allow their status to be queried. Finished tasks can be explicitly pruned with the ``prune=true`` parameter. For example: :: http://localhost:8182/tasks/3?prune=true Prune has no effect on unfinished tasks. Examples ^^^^^^^^ When the command is invoked, it returns a result such as the following XML-formatted response. :: 5 RUNNING {command description} Connecting to http://overpass-api.de/api/interpreter... 0.0 Or the JSON format: :: {"task": { "id":5, "status":"RUNNING", "description":"osm download filter: null, bbox: -32.9621,-60.6309,-32.9541,-60.6154", "href":"http://localhost:8182/tasks/5.json" "progress" : { "task" : "Connecting to http://overpass-api.de/api/interpreter...", "amount" : 0.0 } } } Note, the ``atom:link`` in the XML response and the ``href`` property in the JSON response, represent the status polling URL for the specific task ID. The ``status`` attribute will have one of the following values: ``WAITING``, ``RUNNING``, ``FINISHED``, ``FAILED``, ``CANCELLED``. ``WAITING`` means that there are other tasks being run in the thread pool and this one has been scheduled to be run as soon as a spot frees up in the thread pool. The others are self-explanatory. The content of the task query response varies slightly depending on the task status. Running tasks may or may not contain a progress indicator. It will depend on the type of task and how far along the task is at the point the response is generated. :: 4 RUNNING Importing geopackage... Importing into GeoGig repo... 1397120.0 Successfully finished tasks may contain a result summary which is specific to the command executed. The following is an example of the result for a successful OSM import operation. :: 5 FINISHED Importing geopackage.... 17218621 1412698140574 901852 865542 35778 4 And failed tasks contain an exception report. :: 7 FAILED Importing geopackage... Nothing to commit after bea73023a9452a9d64f64264d2911ce1ec2b47f2