Service Task Framework#

The Sample Service implements the ServiceTask Framework. The Service Task Framework is a framework for asynchronous bulk task execution, to allow services to execute long-running tasks. There are four service-specific task state endpoints that can be used to get information about the tasks or abort them.

These endpoints are:

Get Service Task#

This endpoint fetches a service task based on the Service Task ID using a GET operation.

curl -X GET -H "Argus-API-Key: my/api/key" -H "Content-Type: application/json" https://api.mnemonic.no/sampledb/v2/sample/servicetask/{taskID}

List Service Task#

This endpoint lists service tasks using a GET operation.

curl -X GET -H "Argus-API-Key: my/api/key" -H "Content-Type: application/json" https://api.mnemonic.no/sampledb/v2/sample/servicetask/

Search Service Task#

This endpoint lists service tasks using a POST operation with search criteria. One example of a service task search is:

curl -X POST -H "Argus-API-Key: my/api/key" -H "Content-Type: application/json" https://api.mnemonic.no/sampledb/v2/servicetask/search -d '{
  "operation": [
    "reindexSampleResource"
  ],
  "state": [
    "pending"
  ],
  "user": [
    "olan"
  ],
  "parentTask": [
    "3fa85f64-5717-4562-b3fc-2c963f66afa6"
  ],
  "startTimestamp": 9007199254740991,
  "endTimestamp": 9007199254740991,
  "timeFieldStrategy": [
    "all"
  ],
  "timeMatchStrategy": "any",
  "limit": 1073741824,
  "offset": 1073741824
}'

Abort Service Task#

This endpoint aborts the running task using a DELETE operation with a service task ID

curl -X DELETE -H "Argus-API-Key: my/api/key" -H "Content-Type: application/json" https://api.mnemonic.no/sampledb/v2/sample/servicetask/{taskID}

Reindexing Elasticsearch (Samples and Submissions)#

Reindexing Elasticsearch can be done using a service task. The task will be distributed to different nodes in the cluster, and will survive restarting the nodes, though not a full cluster shutdown.

To start a reindexing job, make a POST request against /sampledb/v2/servicetask/reindex. The endpoint takes in parameters like which DC you want to reindex and if you want to reindex Samples and/or submissions within the given time range. Start and end timestamp is required. If you choose to not set resource or DC, the default options will be to reindex only Samples for both DCs.

After starting a reindex, a correlationID will get returned in the response. To find the corresponding service tasks that have started, use the search service task endpoint with the correlationID as a criteria.

Example queries#

To reindex all Samples and Submissions for both DCs the last 2 days

curl -X POST 'https://devapi.mnemonic.no/sampledb/v2/servicetask/reindex' \
-H 'Content-Type: application/json' -H "Argus-API-Key: my/api/key" \
-d '{
  "startTimestamp": "-2d",
  "endTimestamp": "now",
  "resource": "all",
  "dataCenter": "all"
  }'

To reindex only Submissions in SVG the last week, going from start timestamp to end timestamp (reverse is default)

curl -X POST 'https://devapi.mnemonic.no/sampledb/v2/servicetask/reindex' \
-H 'Content-Type: application/json' -H "Argus-API-Key: my/api/key" \
-d '{
"startTimestamp": "-1w",
"endTimestamp": "now",
"reversed": "false",
"resource": "submission",
"dataCenter": "svg"
}'