// CreateNextRun creates the next run for the given task.
// Refer to the documentation for SetTaskPeriod to understand how the times are determined.
510296
func (d *TaskControlService) CreateNextRun(ctx context.Context, taskID influxdb.ID, now int64) (backend.RunCreation, error) {
	d.mu.Lock()
	defer d.mu.Unlock()
	if !taskID.Valid() {
		return backend.RunCreation{}, errors.New("invalid task id")
	}
	tid := taskID

	task, ok := d.tasks[tid]
	if !ok {
		panic(fmt.Sprintf("meta not set for task with ID %s", tid))
	}

	if len(d.manualRuns) != 0 {
		run := d.manualRuns[0]
		d.manualRuns = d.manualRuns[1:]
		runs, ok := d.runs[tid]
		if !ok {
			runs = make(map[influxdb.ID]*influxdb.Run)
		}
		runs[run.ID] = run
		d.runs[task.ID] = runs
		now, err := time.Parse(time.RFC3339, run.ScheduledFor)
		next, _ := d.nextDueRun(ctx, taskID)
		if err == nil {
			rc := backend.RunCreation{
				Created: backend.QueuedRun{
					TaskID: task.ID,
					RunID:  run.ID,
					Now:    now.Unix(),
				},
				NextDue:  next,
				HasQueue: len(d.manualRuns) != 0,
			}
			d.created[tid.String()+rc.Created.RunID.String()] = rc.Created
			d.totalRunsCreated[taskID]++
			return rc, nil
		}
	}

	rc, err := d.createNextRun(task, now)
	if err != nil {
		return backend.RunCreation{}, err
	}
	rc.Created.TaskID = taskID
	d.created[tid.String()+rc.Created.RunID.String()] = rc.Created
	d.totalRunsCreated[taskID]++
	return rc, nil
}
472696
func (s *ListScheduledAuditsInput) SetNextToken(v string) *ListScheduledAuditsInput {
	s.NextToken = &v
	return s
}
1264245
func (s *ListUsersInGroupInput) SetNextToken(v string) *ListUsersInGroupInput {
	s.NextToken = &v
	return s
}
427576
func (s *ListTargetsByRuleInput) SetNextToken(v string) *ListTargetsByRuleInput {
	s.NextToken = &v
	return s
}
220723
func (s *FilterActivity) SetNext(v string) *FilterActivity {
	s.Next = &v
	return s
}
521161
func (s *DescribeServicesOutput) SetNextToken(v string) *DescribeServicesOutput {
	s.NextToken = &v
	return s
}
869363
func (s *ListAssessmentRunsInput) SetNextToken(v string) *ListAssessmentRunsInput {
	s.NextToken = &v
	return s
}
693630
func (s *DeviceRegistryEnrichActivity) SetNext(v string) *DeviceRegistryEnrichActivity {
	s.Next = &v
	return s
}
344635
func (s *DescribeImportTasksOutput) SetNextToken(v string) *DescribeImportTasksOutput {
	s.NextToken = &v
	return s
}
259326
func (s *DescribeRepositoriesOutput) SetNextToken(v string) *DescribeRepositoriesOutput {
	s.NextToken = &v
	return s
}
231069
func (s *ListUsersInGroupOutput) SetNextToken(v string) *ListUsersInGroupOutput {
	s.NextToken = &v
	return s
}
1236863
func (s *DescribeScalingPlansOutput) SetNextToken(v string) *DescribeScalingPlansOutput {
	s.NextToken = &v
	return s
}
463039
func (s *ListActivitiesOutput) SetNextToken(v string) *ListActivitiesOutput {
	s.NextToken = &v
	return s
}
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
}
1219079
func (s *ListActivitiesInput) SetNextToken(v string) *ListActivitiesInput {
	s.NextToken = &v
	return s
}
1080931
func (s *ListResourcesOutput) SetNextToken(v string) *ListResourcesOutput {
	s.NextToken = &v
	return s
}
951355
func (s *ListAlgorithmsOutput) SetNextToken(v string) *ListAlgorithmsOutput {
	s.NextToken = &v
	return s
}