Tasks API
Introduction
This set of endpoints allows us to interact with tasks that have been created in the repository manager administrative UI.
Endpoints
List Tasks
GET /service/rest/v1/tasks
This endpoint allows us to iterate through a listing of all the existing tasks.
Let's get a listing of the current tasks:
curl -u admin:admin123 -H 'accept: application/json' -X GET 'http://localhost:8081/service/rest/v1/tasks'
{ "items" : [ { "id" : "3f0173a8-c379-44c3-8ba3-2f0d0290bbfa", "name" : "Rebuild all browse trees", "type" : "create.browse.nodes", "message" : null, "currentState" : "WAITING", "lastRunResult" : null, "nextRun" : null, "lastRun" : null }, { "id" : "dbb1f322-907a-4424-ad82-8d0a89deabe1", "name" : "Rebuild all search indices", "type" : "repository.rebuild-index", "message" : null, "currentState" : "WAITING", "lastRunResult" : null, "nextRun" : null, "lastRun" : null }, { "id" : "07fa0c5d-8217-45da-91d3-fdfe9452e21f", "name" : "Publish all maven indices", "type" : "repository.maven.publish-dotindex", "message" : null, "currentState" : "WAITING", "lastRunResult" : null, "nextRun" : null, "lastRun" : null }, { "id" : "2c8fd1f8-2395-4576-a172-a68089bb2ef7", "name" : "Compact default blob store", "type" : "blobstore.compact", "message" : null, "currentState" : "WAITING", "lastRunResult" : null, "nextRun" : null, "lastRun" : null }, { "id" : "0261aed9-9f29-447b-8794-f21693b1f9ac", "name" : "Hello World", "type" : "script", "message" : null, "currentState" : "WAITING", "lastRunResult" : null, "nextRun" : null, "lastRun" : null } ], "continuationToken" : null }
This endpoint uses a pagination strategy that can be used to iterate through all the tasks if desired.
In this case, we only have one page of results as signified by the null
continuationToken
.
Get Task
GET /service/rest/v1/tasks/{id}
This endpoint allows us to get the details about in individual task.
Let's take a look at the details for the "Hello World" task (i.e. id=0261aed9-9f29-447b-8794-f21693b1f9ac
):
curl -u admin:admin123 -X GET 'http://localhost:8081/service/rest/v1/tasks/0261aed9-9f29-447b-8794-f21693b1f9ac'
{ "id" : "0261aed9-9f29-447b-8794-f21693b1f9ac", "name" : "Hello World", "type" : "script", "message" : null, "currentState" : "WAITING", "lastRunResult" : null, "nextRun" : null, "lastRun" : null }
Run Task
POST /service/rest/v1/tasks/{id}/run
This endpoint allows us to run an individual task.
For example, to run the "Hello World" task from above:
curl -u admin:admin123 -X POST 'http://localhost:8081/service/rest/v1/tasks/0261aed9-9f29-447b-8794-f21693b1f9ac/run'
HTTP/1.1 204 No Content Date: Mon, 22 Jan 2018 22:19:47 GMT ...
Stop Task
POST /service/rest/v1/tasks/{id}/stop
This endpoint allows us to stop an individual task. This is the equivalent of cancelling a task in the repository manager UI. Note that not all tasks will respond to a cancellation request.
For example to stop the "Hello World" task:
curl -u admin:admin123 -X POST 'http://localhost:8081/service/rest/v1/tasks/0261aed9-9f29-447b-8794-f21693b1f9ac/stop'
In this example the "Hello World" task was not running when the stop request was made. We will get a 409 response code that signifies that the requested task was not currently running:
HTTP/1.1 409 Conflict Content-Length: 0 Date: Mon, 22 Jan 2018 22:22:33 GMT ...