MCPcopy Create free account
hub / github.com/golang/appengine / AddMulti

Function AddMulti

v2/taskqueue/taskqueue.go:311–354  ·  view source on GitHub ↗

AddMulti adds multiple tasks to a named queue. An empty queue name means that the default queue will be used. AddMulti returns a slice of equivalent tasks with defaults filled in, including setting each task's Name field to the chosen name if the original was empty. If a given task is badly formed o

(c context.Context, tasks []*Task, queueName string)

Source from the content-addressed store, hash-verified

309// each task's Name field to the chosen name if the original was empty.
310// If a given task is badly formed or could not be added, an appengine.MultiError is returned.
311func AddMulti(c context.Context, tasks []*Task, queueName string) ([]*Task, error) {
312 req := &pb.TaskQueueBulkAddRequest{
313 AddRequest: make([]*pb.TaskQueueAddRequest, len(tasks)),
314 }
315 me, any := make(appengine.MultiError, len(tasks)), false
316 for i, t := range tasks {
317 req.AddRequest[i], me[i] = newAddReq(c, t, queueName)
318 any = any || me[i] != nil
319 }
320 if any {
321 return nil, me
322 }
323 res := &pb.TaskQueueBulkAddResponse{}
324 if err := internal.Call(c, "taskqueue", "BulkAdd", req, res); err != nil {
325 return nil, err
326 }
327 if len(res.Taskresult) != len(tasks) {
328 return nil, errors.New("taskqueue: server error")
329 }
330 tasksOut := make([]*Task, len(tasks))
331 for i, tr := range res.Taskresult {
332 tasksOut[i] = new(Task)
333 *tasksOut[i] = *tasks[i]
334 tasksOut[i].Method = tasksOut[i].method()
335 if tasksOut[i].Name == "" {
336 tasksOut[i].Name = string(tr.ChosenTaskName)
337 }
338 if *tr.Result != pb.TaskQueueServiceError_OK {
339 if alreadyAddedErrors[*tr.Result] {
340 me[i] = ErrTaskAlreadyAdded
341 } else {
342 me[i] = &internal.APIError{
343 Service: "taskqueue",
344 Code: int32(*tr.Result),
345 }
346 }
347 any = true
348 }
349 }
350 if any {
351 return tasksOut, me
352 }
353 return tasksOut, nil
354}
355
356// Delete deletes a task from a named queue.
357func Delete(c context.Context, task *Task, queueName string) error {

Callers 1

TestAddMultiFunction · 0.70

Calls 3

CallFunction · 0.92
newAddReqFunction · 0.70
methodMethod · 0.45

Tested by 1

TestAddMultiFunction · 0.56

Used in the wild real call sites across dependent graphs

searching dependent graphs…