// tqTask returns a taskqueue task for an archive task.
420133
func tqTask(task *logdog.ArchiveTask) (*taskqueue.Task, error) {
	payload, err := proto.Marshal(task)
	return &taskqueue.Task{
		Name:    task.TaskName,
		Payload: payload,
		Method:  "PULL",
	}, err
}
1272917
func (c *Client) CreateTask(tr TaskRequest) (task Task, err error) {
	bodyReader, err := createReader(tr)
	if err != nil {
		return task, err
	}

	request := fmt.Sprintf("/v3/apps/%s/tasks", tr.DropletGUID)
	req := c.NewRequestWithBody("POST", request, bodyReader)

	resp, err := c.DoRequest(req)
	if err != nil {
		return task, errors.Wrap(err, "Error creating task")
	}
	defer resp.Body.Close()

	body, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		return task, errors.Wrap(err, "Error reading task after creation")
	}

	err = json.Unmarshal(body, &task)
	if err != nil {
		return task, errors.Wrap(err, "Error unmarshaling task")
	}
	return task, err
}
717251
func (c oauthClient) UpdateTask(task wl.Task) (wl.Task, error) {
	err := c.validateRecurrence(task.RecurrenceType, task.RecurrenceCount)
	if err != nil {
		return wl.Task{}, err
	}

	origTask, err := c.Task(task.ID)
	if err != nil {
		return wl.Task{}, err
	}

	tuc := TaskUpdateConfig{
		Title:     task.Title,
		Revision:  task.Revision,
		Completed: task.Completed,
		Starred:   task.Starred,
		ListID:    task.ListID,

		Remove: []string{},
	}

	if origTask.AssigneeID == task.AssigneeID {
		tuc.AssigneeID = origTask.AssigneeID
	} else {
		if task.AssigneeID == 0 {
			tuc.Remove = append(tuc.Remove, "assignee_id")
		} else {
			tuc.AssigneeID = task.AssigneeID
		}
	}

	if origTask.DueDate == task.DueDate {
		tuc.DueDate = dueDateToString(origTask.DueDate)
	} else {
		if task.DueDate.IsZero() {
			tuc.Remove = append(tuc.Remove, "due_date")
		} else {
			tuc.DueDate = dueDateToString(task.DueDate)
		}
	}

	if origTask.RecurrenceCount == task.RecurrenceCount &&
		origTask.RecurrenceType == task.RecurrenceType {
		tuc.RecurrenceCount = origTask.RecurrenceCount
		tuc.RecurrenceType = origTask.RecurrenceType
	} else {
		if task.RecurrenceCount == 0 {
			tuc.Remove = append(tuc.Remove, "recurrence_type")
			tuc.Remove = append(tuc.Remove, "recurrence_count")
		} else {
			tuc.RecurrenceCount = task.RecurrenceCount
			tuc.RecurrenceType = task.RecurrenceType
		}
	}

	body, err := json.Marshal(tuc)
	if err != nil {
		return wl.Task{}, err
	}

	url := fmt.Sprintf(
		"%s/tasks/%d",
		c.apiURL,
		task.ID,
	)

	req, err := c.newPatchRequest(url, body)
	if err != nil {
		return wl.Task{}, err
	}

	resp, err := c.do(req)
	if err != nil {
		return wl.Task{}, err
	}

	if resp.StatusCode != http.StatusOK {
		return wl.Task{}, fmt.Errorf("Unexpected response code %d - expected %d", resp.StatusCode, http.StatusOK)
	}

	transport := transportTask{}
	err = json.NewDecoder(resp.Body).Decode(&transport)
	if err != nil {
		return wl.Task{}, err
	}
	return taskFromTransport(transport)
}
738324
func (e *engineImpl) execKickTriageTask(c context.Context, tqTask proto.Message) error {
	return e.kickTriageNow(c, tqTask.(*internal.KickTriageTask).JobId)
}
633464
func (s *Service) CreateTask(ctx context.Context, tc influxdb.TaskCreate) (*influxdb.Task, error) {
	var t *influxdb.Task
	err := s.kv.Update(ctx, func(tx Tx) error {
		task, err := s.createTask(ctx, tx, tc)
		if err != nil {
			return err
		}
		t = task
		return nil
	})
	if err != nil {
		return nil, err
	}

	return t, nil
}
795408
func (t TaskService) CreateTask(ctx context.Context, tsk *platform.Task) error {
	u, err := newURL(t.Addr, tasksPath)
	if err != nil {
		return err
	}

	taskBytes, err := json.Marshal(tsk)
	if err != nil {
		return err
	}

	req, err := http.NewRequest("POST", u.String(), bytes.NewReader(taskBytes))
	if err != nil {
		return err
	}

	req.Header.Set("Content-Type", "application/json")
	SetToken(t.Token, req)

	hc := newClient(u.Scheme, t.InsecureSkipVerify)

	resp, err := hc.Do(req)
	if err != nil {
		return err
	}
	defer resp.Body.Close()

	if err := CheckError(resp); err != nil {
		return err
	}

	var tr taskResponse
	if err := json.NewDecoder(resp.Body).Decode(&tr); err != nil {
		return err
	}
	*tsk = tr.Task

	return nil
}
384672
func getTask(res *http.Response, e error) (*Task, error) {
	if e != nil {
		return nil, e
	}
	var task Task
	err := json.NewDecoder(res.Body).Decode(&task)
	if err != nil {
		return nil, err
	}
	if task.State == "ERROR" {
		// Critical: return task as well, so that it can be examined
		// for error details.
		return &task, TaskError{task.ID, getFailedStep(&task)}
	}
	return &task, nil
}
662267
func (f *PlatformFilter) SetTask(t *api.Task) bool {
	placement := t.Spec.Placement
	if placement != nil {
		// copy the platform information
		f.supportedPlatforms = placement.Platforms
		if len(placement.Platforms) > 0 {
			return true
		}
	}
	return false
}
1248431
func (c oauthClient) DeleteTask(task wl.Task) error {
	url := fmt.Sprintf(
		"%s/tasks/%d?revision=%d",
		c.apiURL,
		task.ID,
		task.Revision,
	)

	req, err := c.newDeleteRequest(url)
	if err != nil {
		return err
	}

	resp, err := c.do(req)
	if err != nil {
		return err
	}

	if resp.StatusCode != http.StatusNoContent {
		return fmt.Errorf("Unexpected response code %d - expected %d", resp.StatusCode, http.StatusNoContent)
	}

	return nil
}
472193
func reqProcessingTask(c *asyncConnHdl, ctl workerCtl) (ic *interrupt_code, ts *taskStatus) {

	var err error
	var errmsg string

	bytecnt := 0
	blen := 0
	bufsize := c.spec().wBufSize
	var sig interrupt_code

	select {
	case req := <-c.pendingReqs:
		blen, err := c.processAsyncRequest(req)
		if err != nil {
			errmsg = fmt.Sprintf("processAsyncRequest error in initial phase")
			goto proc_error
		}
		bytecnt += blen
	case sig := <-ctl:
		return &sig, &ok_status
	}

	for bytecnt < bufsize {
		select {
		case req := <-c.pendingReqs:
			blen, err = c.processAsyncRequest(req)
			if err != nil {
				errmsg = fmt.Sprintf("processAsyncRequest error in batch phase")
				goto proc_error
			}
			if blen > 0 {
				bytecnt += blen
			} else {
				bytecnt = 0
			}

		case sig = <-ctl:
			ic = &sig
			goto done

		default:
			goto done
		}
	}

done:
	c.writer.Flush()
	return ic, &ok_status

proc_error:
	log.Println(errmsg, err)
	return nil, &taskStatus{snderr, err}
}
980404
func (f *HostPortFilter) SetTask(t *api.Task) bool {
	if t.Endpoint != nil {
		for _, port := range t.Endpoint.Ports {
			if port.PublishMode == api.PublishModeHost && port.PublishedPort != 0 {
				f.t = t
				return true
			}
		}
	}

	return false
}
569859
func (m *JobExecutor) NewTask(p plan.Task) Task {
	if p.IsParallel() {
		return NewTaskParallel(m.Ctx)
	}
	return NewTaskSequential(m.Ctx)
}
802788
func (f *PluginFilter) SetTask(t *api.Task) bool {
	c := t.Spec.GetContainer()

	var volumeTemplates bool
	if c != nil {
		for _, mount := range c.Mounts {
			if referencesVolumePlugin(mount) {
				volumeTemplates = true
				break
			}
		}
	}

	if (c != nil && volumeTemplates) || len(t.Networks) > 0 || t.Spec.LogDriver != nil {
		f.t = t
		return true
	}

	return false
}
461867
func (r *Orchestrator) FixTask(ctx context.Context, batch *store.Batch, t *api.Task) {
	// If we already set the desired state past TaskStateRunning, there is no
	// further action necessary.
	if t.DesiredState > api.TaskStateRunning {
		return
	}

	var (
		n       *api.Node
		service *api.Service
	)
	batch.Update(func(tx store.Tx) error {
		if t.NodeID != "" {
			n = store.GetNode(tx, t.NodeID)
		}
		if t.ServiceID != "" {
			service = store.GetService(tx, t.ServiceID)
		}
		return nil
	})

	if !orchestrator.IsReplicatedService(service) {
		return
	}

	if t.Status.State > api.TaskStateRunning ||
		(t.NodeID != "" && orchestrator.InvalidNode(n)) {
		r.restartTasks[t.ID] = struct{}{}
		return
	}
}
536056
func AddTask(t *automationpb.TaskContainer, taskName string, parameters map[string]string) {
	t.ParallelTasks = append(t.ParallelTasks, NewTask(taskName, parameters))
}
874924
func clearTask(responsec responder) task {
	return func(c *cache) error {
		var errs []error
		for id, bucket := range c.buckets {
			switch bucket.status {
			case statusLoading:
				for _, waiter := range bucket.waiters {
					waiter <- func() (Cacheable, error) {
						return nil, errors.New(ErrDiscardedWhileLoading, errorMessages, id)
					}
				}
			case statusLoaded:
				if err := bucket.cacheable.Discard(); err != nil {
					errs = append(errs, err)
				}
			}
		}
		c.buckets = make(map[string]*bucket)
		var err error
		if len(errs) > 0 {
			err = errors.Collect(errs...)
		}
		responsec <- func() (Cacheable, error) {
			return nil, err
		}
		return nil
	}
}
773210
func benchTask(taskspec taskSpec, iterations int, workers int, printReport bool) (delta time.Duration, err error) {
	// channel to signal completion
	signal := make(chan int, workers)

	// spec and initialize an AsyncClient
	// will flush your db13 as noted in README ..
	spec := redis.DefaultSpec().Db(13).Password("go-redis")
	client, e := redis.NewAsynchClientWithSpec(spec)
	if e != nil {
		log.Println("Error creating client for worker: ", e)
		return -1, e
	}

	defer client.Quit()

	// panics
	setup(client)

	t0 := time.Now()
	for i := 0; i < workers; i++ {
		id := fmt.Sprintf("%d", i)
		go taskspec.task(id, signal, client, iterations)
	}

	// wait for completion
	for i := 0; i < workers; i++ {
		<-signal
	}
	delta = time.Now().Sub(t0)

	if printReport {
		report(taskspec.name, workers, delta, iterations*workers)
	}

	return
}