MCPcopy Create free account
hub / github.com/cloudreve/cloudreve / CreateTask

Method CreateTask

pkg/cluster/node.go:253–284  ·  view source on GitHub ↗
(ctx context.Context, taskType string, state string)

Source from the content-addressed store, hash-verified

251}
252
253func (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
286func (n *slaveNode) GetTask(ctx context.Context, id int, clearOnComplete bool) (*SlaveTaskSummary, error) {
287 resp, err := n.client.Request(

Callers

nothing calls this directly

Calls 8

WithContextFunction · 0.92
WithLoggerFunction · 0.92
FromContextFunction · 0.92
NewErrorFromResponseFunction · 0.92
DecodeResponseMethod · 0.80
CheckHTTPResponseMethod · 0.80
GobDecodeMethod · 0.80
RequestMethod · 0.65

Tested by

no test coverage detected