Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
404 views
in Technique[技术] by (71.8m points)

nexus - Detecting when a task has finished through REST APIs

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?

question from:https://stackoverflow.com/questions/65847936/detecting-when-a-task-has-finished-through-rest-apis

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...