code: func NewTask(cluster *api.Cluster, service *api.Service, slot uint64, nodeID string) *api.Task {
  	var logDriver *api.Driver
  	if service.Spec.Task.LogDriver != nil {
  		// use the log driver specific to the task, if we have it.
  		logDriver = service.Spec.Task.LogDriver
  	} else if cluster != nil {
  		// pick up the cluster default, if available.
  		logDriver = cluster.Spec.TaskDefaults.LogDriver // nil is okay here.
  	}
  
  	taskID := identity.NewID()
  	task := api.Task{
  		ID:                 taskID,
  		ServiceAnnotations: service.Spec.Annotations,
  		Spec:               service.Spec.Task,
  		SpecVersion:        service.SpecVersion,
  		ServiceID:          service.ID,
  		Slot:               slot,
  		Status: api.TaskStatus{
  			State:     api.TaskStateNew,
  			Timestamp: ptypes.MustTimestampProto(time.Now()),
  			Message:   "created",
  		},
  		Endpoint: &api.Endpoint{
  			Spec: service.Spec.Endpoint.Copy(),
  		},
  		DesiredState: api.TaskStateRunning,
  		LogDriver:    logDriver,
  	}
  
  	// In global mode we also set the NodeID
  	if nodeID != "" {
  		task.NodeID = nodeID
  	}
  
  	return &task
  }
docs: // NewTask creates a new task.