确认收到投递的工作行
确认收到已投递的工作行(queued → starting),记录 acknowledged_at——不在固定 ack 窗口(5000ms,由后台 sweeper 回收)内确认,工作行将被退回队列。投递后须立即 Ack,慢 executor 启动须在 Ack 之后。过期 token 将被拒绝并返回 412 failed_precondition_error。
POST
/
v1
/
environments
/
{environment_id}
/
work
/
{id}
/
ack
确认收到投递的工作行
curl --request POST \
--url https://api.moonshot.cn/v1/environments/{environment_id}/work/{id}/ack \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"worker_id": "worker-1",
"generation": 1
}
'import requests
url = "https://api.moonshot.cn/v1/environments/{environment_id}/work/{id}/ack"
payload = {
"worker_id": "worker-1",
"generation": 1
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({worker_id: 'worker-1', generation: 1})
};
fetch('https://api.moonshot.cn/v1/environments/{environment_id}/work/{id}/ack', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.moonshot.cn/v1/environments/{environment_id}/work/{id}/ack",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'worker_id' => 'worker-1',
'generation' => 1
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.moonshot.cn/v1/environments/{environment_id}/work/{id}/ack"
payload := strings.NewReader("{\n \"worker_id\": \"worker-1\",\n \"generation\": 1\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.moonshot.cn/v1/environments/{environment_id}/work/{id}/ack")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"worker_id\": \"worker-1\",\n \"generation\": 1\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.moonshot.cn/v1/environments/{environment_id}/work/{id}/ack")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"worker_id\": \"worker-1\",\n \"generation\": 1\n}"
response = http.request(request)
puts response.read_body{
"id": "<string>",
"session_id": "<string>",
"environment_id": "<string>",
"status": "queued",
"generation": 2,
"lease_ttl_ms": 123,
"created_at": "2023-11-07T05:31:56Z",
"worker_id": "<string>",
"claimed_at": "2023-11-07T05:31:56Z",
"acknowledged_at": "2023-11-07T05:31:56Z",
"started_at": "2023-11-07T05:31:56Z",
"latest_heartbeat_at": "2023-11-07T05:31:56Z",
"stop_requested_at": "2023-11-07T05:31:56Z",
"stopped_at": "2023-11-07T05:31:56Z",
"secret": "<string>"
}{
"error": {
"type": "invalid_parameter_error",
"message": "<string>",
"param": "<string>",
"request_id": "<string>"
}
}{
"error": {
"type": "invalid_parameter_error",
"message": "<string>",
"param": "<string>",
"request_id": "<string>"
}
}{
"error": {
"type": "invalid_parameter_error",
"message": "<string>",
"param": "<string>",
"request_id": "<string>"
}
}{
"error": {
"type": "invalid_parameter_error",
"message": "<string>",
"param": "<string>",
"request_id": "<string>"
}
}{
"error": {
"type": "invalid_parameter_error",
"message": "<string>",
"param": "<string>",
"request_id": "<string>"
}
}{
"error": {
"type": "invalid_parameter_error",
"message": "<string>",
"param": "<string>",
"request_id": "<string>"
}
}请求头
请求体
application/json
响应
已确认的工作行,状态转为 starting。
自托管工作队列中的一行:其沙箱工具调用在环境属主的 worker 上执行的会话。GET /v1/environments/{environment_id}/work/poll 投递工作行(ack 前仍为 queued);其携带的 generation 是 fencing token,后续每次 ack、心跳、stop 都必须携带。user.tool_result 回写无需显式携带:secret 中的会话级 work token 已绑定签发代次,平台由它派生 fencing。
此页面对您有帮助吗?
⌘I
确认收到投递的工作行
curl --request POST \
--url https://api.moonshot.cn/v1/environments/{environment_id}/work/{id}/ack \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"worker_id": "worker-1",
"generation": 1
}
'import requests
url = "https://api.moonshot.cn/v1/environments/{environment_id}/work/{id}/ack"
payload = {
"worker_id": "worker-1",
"generation": 1
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({worker_id: 'worker-1', generation: 1})
};
fetch('https://api.moonshot.cn/v1/environments/{environment_id}/work/{id}/ack', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.moonshot.cn/v1/environments/{environment_id}/work/{id}/ack",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'worker_id' => 'worker-1',
'generation' => 1
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.moonshot.cn/v1/environments/{environment_id}/work/{id}/ack"
payload := strings.NewReader("{\n \"worker_id\": \"worker-1\",\n \"generation\": 1\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.moonshot.cn/v1/environments/{environment_id}/work/{id}/ack")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"worker_id\": \"worker-1\",\n \"generation\": 1\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.moonshot.cn/v1/environments/{environment_id}/work/{id}/ack")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"worker_id\": \"worker-1\",\n \"generation\": 1\n}"
response = http.request(request)
puts response.read_body{
"id": "<string>",
"session_id": "<string>",
"environment_id": "<string>",
"status": "queued",
"generation": 2,
"lease_ttl_ms": 123,
"created_at": "2023-11-07T05:31:56Z",
"worker_id": "<string>",
"claimed_at": "2023-11-07T05:31:56Z",
"acknowledged_at": "2023-11-07T05:31:56Z",
"started_at": "2023-11-07T05:31:56Z",
"latest_heartbeat_at": "2023-11-07T05:31:56Z",
"stop_requested_at": "2023-11-07T05:31:56Z",
"stopped_at": "2023-11-07T05:31:56Z",
"secret": "<string>"
}{
"error": {
"type": "invalid_parameter_error",
"message": "<string>",
"param": "<string>",
"request_id": "<string>"
}
}{
"error": {
"type": "invalid_parameter_error",
"message": "<string>",
"param": "<string>",
"request_id": "<string>"
}
}{
"error": {
"type": "invalid_parameter_error",
"message": "<string>",
"param": "<string>",
"request_id": "<string>"
}
}{
"error": {
"type": "invalid_parameter_error",
"message": "<string>",
"param": "<string>",
"request_id": "<string>"
}
}{
"error": {
"type": "invalid_parameter_error",
"message": "<string>",
"param": "<string>",
"request_id": "<string>"
}
}{
"error": {
"type": "invalid_parameter_error",
"message": "<string>",
"param": "<string>",
"request_id": "<string>"
}
}