// NewSimpleTask returns a new *SimpleTask instance.
5777
func NewSimpleTask() *SimpleTask {
	return &SimpleTask{
		ch: make(chan *Update),
		wg: new(sync.WaitGroup),
	}
}
536056
func AddTask(t *automationpb.TaskContainer, taskName string, parameters map[string]string) {
	t.ParallelTasks = append(t.ParallelTasks, NewTask(taskName, parameters))
}
1230875
func (*CallingGoroutineDispatcher) DispatchTask(task *swf.PollForActivityTaskOutput, handler func(*swf.PollForActivityTaskOutput)) {
	handler(task)
}
1036716
func NewStoreTaskMeta(req CreateTaskRequest, o options.Options) StoreTaskMeta {
	stm := StoreTaskMeta{
		MaxConcurrency:  int32(o.Concurrency),
		Status:          string(req.Status),
		LatestCompleted: req.ScheduleAfter,
		EffectiveCron:   o.EffectiveCronString(),
		Offset:          int32(o.Offset / time.Second),
	}

	if stm.Status == "" {
		stm.Status = string(DefaultTaskStatus)
	}

	if o.Every != 0 {
		t := time.Unix(stm.LatestCompleted, 0).Truncate(o.Every).Unix()
		if t == stm.LatestCompleted {
			// For example, every 1m truncates to exactly on the minute.
			// But the input request is schedule after, not "on or after".
			// Add one interval.
			t += int64(o.Every / time.Second)
		}
		stm.LatestCompleted = t
	}

	return stm
}
1618
func NewListTask(msg string) *ListTask {
	return &ListTask{
		msg: msg,
		ch:  make(chan *Update, 1),
	}
}
1287142
func (i *FuncInterceptor) AfterTaskComplete(activity *swf.PollForActivityTaskOutput, result interface{}) {
	if i.AfterTaskCompleteFn != nil {
		i.AfterTaskCompleteFn(activity, result)
	}
}
143878
func newSyncMemBatch() *syncMemBatch {
	return &syncMemBatch{
		batch: make(map[common.Hash][]byte),
		order: make([]common.Hash, 0, 256),
	}
}
283981
func NewSimpleWaitGen(init func(WaitInterface)) *WaitGen {
	return &WaitGen{
		nil,
		func() WaitInterface {
			nt := NewWait()
			init(nt)
			return nt
		},
	}
}
1078061
func NewSimpleDB(region Region, key aws.AccessKey) (db SimpleDB, err error) {
	// Open an appropriate HTTP connection.
	endpoint := &url.URL{
		Scheme: "https",
		Host:   string(region),
	}

	httpConn, err := conn.NewHttpConn(endpoint)
	if err != nil {
		err = fmt.Errorf("Opening HTTP connection: %v", err)
		return
	}

	// Create a request signer.
	signer, err := conn.NewSigner(key, endpoint.Host)
	if err != nil {
		err = fmt.Errorf("Creating signer: %v", err)
		return
	}

	// Create a connection to the server.
	c, err := conn.NewConn(key, httpConn, signer, time.RealClock())
	if err != nil {
		err = fmt.Errorf("Creating connection: %v", err)
		return
	}

	return newSimpleDB(c)
}
607318
func NewSimpleLogger(w io.Writer, lvl Level, prefix string, color bool) *Logger {
	l := &Logger{}
	r := NewReceiver(w, prefix)
	r.Color = color
	r.Level = lvl
	l.Receivers = []*Receiver{r}
	l.Active = true
	return l
}
192126
func (conn *ProtoConnection) NewSyncPublisher(topic string) (messaging.ProtoPublisher, error) {
	return &protoSyncPublisherKafka{conn, topic}, nil
}
505423
func (s *globalTaskService) TaskTrack(ctx types.Context) *types.Task {
	return &s.taskTrack(ctx).Task
}
1122403
func NewSimpleConnector(target string, options map[string]string) Connector {
	return &simpleConnector{backendAddr: target, opts: options}
}
863720
func updateTaskStatus(t *api.Task, newStatus api.TaskState, message string) {
	t.Status = api.TaskStatus{
		State:     newStatus,
		Message:   message,
		Timestamp: ptypes.MustTimestampProto(time.Now()),
	}
}
1278978
func NewSimpleSession(userData interface{}, sid string) *SimpleSession {
	var s = sid
	if sid == "" {
		s = UDID()
	}
	return &SimpleSession{s, userData}
}
586048
func (nodeInfo *NodeInfo) addTask(t *api.Task) bool {
	oldTask, ok := nodeInfo.Tasks[t.ID]
	if ok {
		if t.DesiredState <= api.TaskStateRunning && oldTask.DesiredState > api.TaskStateRunning {
			nodeInfo.Tasks[t.ID] = t
			nodeInfo.ActiveTasksCount++
			nodeInfo.ActiveTasksCountByService[t.ServiceID]++
			return true
		} else if t.DesiredState > api.TaskStateRunning && oldTask.DesiredState <= api.TaskStateRunning {
			nodeInfo.Tasks[t.ID] = t
			nodeInfo.ActiveTasksCount--
			nodeInfo.ActiveTasksCountByService[t.ServiceID]--
			return true
		}
		return false
	}

	nodeInfo.Tasks[t.ID] = t

	reservations := taskReservations(t.Spec)
	resources := nodeInfo.AvailableResources

	resources.MemoryBytes -= reservations.MemoryBytes
	resources.NanoCPUs -= reservations.NanoCPUs

	// minimum size required
	t.AssignedGenericResources = make([]*api.GenericResource, 0, len(resources.Generic))
	taskAssigned := &t.AssignedGenericResources

	genericresource.Claim(&resources.Generic, taskAssigned, reservations.Generic)

	if t.Endpoint != nil {
		for _, port := range t.Endpoint.Ports {
			if port.PublishMode == api.PublishModeHost && port.PublishedPort != 0 {
				portSpec := hostPortSpec{protocol: port.Protocol, publishedPort: port.PublishedPort}
				nodeInfo.usedHostPorts[portSpec] = struct{}{}
			}
		}
	}

	if t.DesiredState <= api.TaskStateRunning {
		nodeInfo.ActiveTasksCount++
		nodeInfo.ActiveTasksCountByService[t.ServiceID]++
	}

	return true
}
1204416
func ValidateTask(task interface{}) error {
	v := reflect.ValueOf(task)
	t := v.Type()

	// Task must be a function
	if t.Kind() != reflect.Func {
		return ErrTaskMustBeFunc
	}

	// Task must return at least a single value
	if t.NumOut() < 1 {
		return ErrTaskReturnsNoValue
	}

	// Last return value must be error
	lastReturnType := t.Out(t.NumOut() - 1)
	errorInterface := reflect.TypeOf((*error)(nil)).Elem()
	if !lastReturnType.Implements(errorInterface) {
		return ErrLastReturnValueMustBeError
	}

	return nil
}