feat(tasks): implement atomic claims and leases
This commit is contained in:
@@ -299,9 +299,9 @@ func (h *Handler) CancelTask(ctx *gin.Context) {
|
||||
)
|
||||
return
|
||||
}
|
||||
_, err := h.service.CancelPending(
|
||||
task, err := h.service.CancelTask(
|
||||
ctx.Request.Context(),
|
||||
CancelPendingInput{
|
||||
CancelTaskInput{
|
||||
TaskID: taskID,
|
||||
IdempotencyKey: cancelKey,
|
||||
},
|
||||
@@ -317,9 +317,13 @@ func (h *Handler) CancelTask(ctx *gin.Context) {
|
||||
h.renderServiceError(ctx, err, "取消失败,请稍后重试。")
|
||||
return
|
||||
}
|
||||
notice := "cancel-requested"
|
||||
if task.Status == "CANCELED" {
|
||||
notice = "canceled"
|
||||
}
|
||||
ctx.Redirect(
|
||||
http.StatusSeeOther,
|
||||
"/tasks/"+pathEscape(taskID)+"?notice=canceled",
|
||||
"/tasks/"+pathEscape(taskID)+"?notice="+notice,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -644,6 +648,8 @@ func detailNotice(value string) string {
|
||||
switch value {
|
||||
case "canceled":
|
||||
return "任务已取消,不会自动恢复。"
|
||||
case "cancel-requested":
|
||||
return "已请求设备安全停止;设备确认前任务仍保持当前执行状态。"
|
||||
case "cancel-conflict":
|
||||
return "任务状态已变化,当前不能取消。"
|
||||
default:
|
||||
@@ -736,19 +742,20 @@ type newTaskPageView struct {
|
||||
}
|
||||
|
||||
type taskDetailView struct {
|
||||
ID string
|
||||
Title string
|
||||
SKU string
|
||||
Description string
|
||||
Quantity int64
|
||||
MaxBudget string
|
||||
Status string
|
||||
StatusLabel string
|
||||
StatusClass string
|
||||
ReferenceAssetID string
|
||||
CreatedAt time.Time
|
||||
UpdatedAt time.Time
|
||||
CanCancel bool
|
||||
ID string
|
||||
Title string
|
||||
SKU string
|
||||
Description string
|
||||
Quantity int64
|
||||
MaxBudget string
|
||||
Status string
|
||||
StatusLabel string
|
||||
StatusClass string
|
||||
ReferenceAssetID string
|
||||
CreatedAt time.Time
|
||||
UpdatedAt time.Time
|
||||
CanCancel bool
|
||||
CancelRequiresAck bool
|
||||
}
|
||||
|
||||
type taskDetailPage struct {
|
||||
@@ -779,7 +786,18 @@ func taskDetailViewFrom(task Task) taskDetailView {
|
||||
ReferenceAssetID: task.ReferenceAssetID,
|
||||
CreatedAt: task.CreatedAt,
|
||||
UpdatedAt: task.UpdatedAt,
|
||||
CanCancel: task.Status == "PENDING",
|
||||
CanCancel: canCancelTaskStatus(task.Status),
|
||||
CancelRequiresAck: task.Status == "RUNNING" ||
|
||||
task.Status == "WAITING_CONFIRMATION",
|
||||
}
|
||||
}
|
||||
|
||||
func canCancelTaskStatus(status string) bool {
|
||||
switch status {
|
||||
case "PENDING", "CLAIMED", "RUNNING", "WAITING_CONFIRMATION":
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user