(ctx context.Context, taskType string, state string)
| 251 | } |
| 252 | |
| 253 | func (n *slaveNode) CreateTask(ctx context.Context, taskType string, state string) (int, error) { |
| 254 | reqBody, err := json.Marshal(&CreateSlaveTask{ |
| 255 | Type: taskType, |
| 256 | State: state, |
| 257 | }) |
| 258 | if err != nil { |
| 259 | return 0, fmt.Errorf("failed to marshal request body: %w", err) |
| 260 | } |
| 261 | |
| 262 | resp, err := n.client.Request( |
| 263 | "PUT", |
| 264 | constants.APIPrefixSlave+"/task", |
| 265 | bytes.NewReader(reqBody), |
| 266 | request.WithContext(ctx), |
| 267 | request.WithLogger(logging.FromContext(ctx)), |
| 268 | ).CheckHTTPResponse(200).DecodeResponse() |
| 269 | if err != nil { |
| 270 | return 0, err |
| 271 | } |
| 272 | |
| 273 | // 处理列取结果 |
| 274 | if resp.Code != 0 { |
| 275 | return 0, serializer.NewErrorFromResponse(resp) |
| 276 | } |
| 277 | |
| 278 | taskId := 0 |
| 279 | if resp.GobDecode(&taskId); taskId > 0 { |
| 280 | return taskId, nil |
| 281 | } |
| 282 | |
| 283 | return 0, fmt.Errorf("unexpected response data: %v", resp.Data) |
| 284 | } |
| 285 | |
| 286 | func (n *slaveNode) GetTask(ctx context.Context, id int, clearOnComplete bool) (*SlaveTaskSummary, error) { |
| 287 | resp, err := n.client.Request( |
nothing calls this directly
no test coverage detected