通过 REST API 检测任务何时完成 [英] Detecting when a task has finished through REST APIs

查看:85
本文介绍了通过 REST API 检测任务何时完成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Sonatype 的 Nexus 存储库服务器提供了一个经典的 REST API.当通过 REST API 触发操作时,调用会立即返回,通过其状态代码指示操作是否启动成功.我正在寻找一种方法来检测工作是否以及何时成功完成.

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"

返回 204 task was run";立即.

which returns a 204 "task was run" immediately.

然而,几分钟后,手动检查表明该任务创建的磁盘文件仍在增长.当然,我可以尝试观察 lsof 的输出,直到该任务似乎完成为止,但这非常不切实际,需要对服务器的 root 访问权限并且还会破坏 REST 设计.

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.

一个 类似问题自 2016 年以来一直没有收到答案,所以我'我会以更笼统的方式提问,希望答案更适用:

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:

REST 客户端如何在与 Sonatype Nexus 3.x 系列服务器通信时检测到服务器端的操作已完全完成?

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?

如果没有这样的方法,您会认为这是 Nexus 的问题还是建议创建自定义解决方法?

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

推荐答案

Nexus 3 有一个 get task API 端点,它会给你关于特定任务的不同信息,包括它的 currentState

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}

取自以下链接文档的示例 API 响应:

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
}

参考:Nexus 获取任务 API 端点文档

这篇关于通过 REST API 检测任务何时完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆