feat: 增加真实采购任务安全模式 (#98)
This commit is contained in:
@@ -123,7 +123,7 @@ func (h *Handler) Claim(c *gin.Context) {
|
||||
}
|
||||
|
||||
// 2. 领取一个任务,只会拿到分配给这个客户端的
|
||||
task, err := service.ClaimNextTask(h.db, clientID, req.SupportedTypes)
|
||||
task, err := service.ClaimNextTask(h.db, clientID, req.SupportedTypes, req.Capabilities.PurchaseMode)
|
||||
if err != nil {
|
||||
log.Printf("task_claim_failed client_id=%s err=%v", clientID, err)
|
||||
apiError(c, http.StatusInternalServerError, "TASK_CLAIM_FAILED",
|
||||
@@ -171,13 +171,14 @@ func taskPayload(t *model.Task) gin.H {
|
||||
}
|
||||
|
||||
return gin.H{
|
||||
"id": t.TaskID,
|
||||
"type": t.TaskType,
|
||||
"version": t.Version,
|
||||
"priority": t.Priority,
|
||||
"payload": payload,
|
||||
"created_at": t.CreatedAt,
|
||||
"updated_at": t.UpdatedAt,
|
||||
"id": t.TaskID,
|
||||
"type": t.TaskType,
|
||||
"execution_mode": t.ExecutionMode,
|
||||
"version": t.Version,
|
||||
"priority": t.Priority,
|
||||
"payload": payload,
|
||||
"created_at": t.CreatedAt,
|
||||
"updated_at": t.UpdatedAt,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"cmautobuy/admin/model"
|
||||
)
|
||||
|
||||
func TestTaskPayload_包含不可变执行模式(t *testing.T) {
|
||||
payload := taskPayload(&model.Task{TaskID: "T-1", TaskType: model.TaskPurchase, ExecutionMode: model.TaskExecutionLive})
|
||||
if payload["execution_mode"] != model.TaskExecutionLive {
|
||||
t.Fatalf("execution_mode=%v", payload["execution_mode"])
|
||||
}
|
||||
}
|
||||
@@ -630,7 +630,12 @@ func (h *Handler) SybCreateTask(c *gin.Context) {
|
||||
}
|
||||
requests = append(requests, service.PurchaseTaskRequest{SybID: sybID, MaxPriceCent: cent})
|
||||
}
|
||||
result, err := service.CreatePurchaseTasks(h.db, currentUser(c), requests, c.PostForm("client_id"))
|
||||
result, err := service.CreatePurchaseTasksWithOptions(h.db, currentUser(c), requests, service.PurchaseTaskOptions{
|
||||
ClientID: c.PostForm("client_id"),
|
||||
ExecutionMode: model.TaskExecutionMode(c.PostForm("execution_mode")),
|
||||
LiveAcknowledged: c.PostForm("live_acknowledged") == "1",
|
||||
LiveConfirmation: c.PostForm("live_confirmation"),
|
||||
})
|
||||
if err != nil {
|
||||
h.sybRedirect(c, "采购任务没有创建:"+err.Error())
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user