0

The Nexus repository server by Sonatype offers a classical REST API. When an operation is triggered through the REST API, the call returns immediately, indicating through its status code whether or not the operation was started successfully. I am looking for a way to detect whether and when a job finished successfully.

In my concrete case, I am starting a backup task that writes out configuration databases in a serialized format to disk:

curl -X POST "$mynexus/service/rest/v1/tasks/$task-id/run" -H "accept: application/json"

which returns a 204 "task was run" immediately.

However, minutes after that happens, a manual check indicates that the on-disk file created by that task is still growing. Of course, I could try watching the output of lsof until that task seems finished, but that would be highly impractical, require root access to the server and also break the REST design.

A similar question here has not received an answer since 2016, so I'll ask in a more general way, in the hope that the answer will be more generally applicable:

How can a REST client detect that an operation has completely finished on the server side when talking to a Sonatype Nexus 3.x series server?

If there is no such way, would you consider that an issue with Nexus or would you recommend to create a custom workaround?

jstarek
  • 1,522
  • 1
  • 12
  • 23

1 Answers1

1

Nexus 3 has a get task API endpoint which will give you different info about a specific task, including its currentState

GET /service/v1/tasks/{id}

Example API response taken from the below linked documentation:

{
  "id" : "0261aed9-9f29-447b-8794-f21693b1f9ac",
  "name" : "Hello World",
  "type" : "script",
  "message" : null,
  "currentState" : "WAITING",
  "lastRunResult" : null,
  "nextRun" : null,
  "lastRun" : null
}

Reference: Nexus get task API endpoint documentation

Zeitounator
  • 38,476
  • 7
  • 53
  • 66
  • Is there any REST API for creating a task scheduler in Nexus 3.x ? – Jessica Jan 04 '23 at 14:13
  • Unfortunately not. There is a groovy API though if scripting is enabled (and there is a REST script API endpoint to create and run scripts). You can find an example script [here](https://github.com/ansible-ThoTeam/nexus3-oss/blob/main/files/groovy/create_task.groovy) (disclaimer: I'm the author). – Zeitounator Jan 04 '23 at 14:26