// NewTaskChain creates the task chain for a specific dogfile and task.
17186
func NewTaskChain(dtasks Dogtasks, task string) (taskChain TaskChain, err error) {
	err = taskChain.generate(dtasks, task)
	if err != nil {
		return
	}
	return
}
483015
func NewChain(nodes ...Node) *Chain {
	chain := &Chain{}
	for _, node := range nodes {
		chain.nodeGroups = append(chain.nodeGroups, NewNodeGroup(node))
	}
	return chain
}
191669
func CredChain(cfg *aws.Config, handlers request.Handlers) *credentials.Credentials {
	return credentials.NewCredentials(&credentials.ChainProvider{
		VerboseErrors: aws.BoolValue(cfg.CredentialsChainVerboseErrors),
		Providers:     CredProviders(cfg, handlers),
	})
}
278300
func (r *ChainResponse) AddChain(chain bees.Chain) {
	r.chains[chain.Name] = &chain
}
855196
func NewToken() (*Token, error) {
	id, err := utils.RandomBytes(tokenIDBytes)
	if err != nil {
		return nil, err
	}

	secret, err := utils.RandomBytes(tokenSecretBytes)
	if err != nil {
		return nil, err
	}

	return &Token{ID: id, Secret: secret}, nil
}
744862
func (pdb *BytesBrokerWatcherRedis) NewTxn() keyval.BytesTxn {
	if pdb.delegate.closed {
		pdb.Error("NewTxn() called on a closed connection")
		return nil
	}
	pdb.Debug("NewTxn()")

	return &Txn{db: pdb.delegate, ops: []op{}, addPrefix: pdb.addPrefix}
}
681814
func (b *Builder) BuildChain(ctx context.Context, middlewares []string) *alice.Chain {
	chain := alice.New()
	for _, name := range middlewares {
		middlewareName := internal.GetQualifiedName(ctx, name)

		chain = chain.Append(func(next http.Handler) (http.Handler, error) {
			constructorContext := internal.AddProviderInContext(ctx, middlewareName)
			if _, ok := b.configs[middlewareName]; !ok {
				return nil, fmt.Errorf("middleware %q does not exist", middlewareName)
			}

			var err error
			if constructorContext, err = checkRecursion(constructorContext, middlewareName); err != nil {
				return nil, err
			}

			constructor, err := b.buildConstructor(constructorContext, middlewareName, *b.configs[middlewareName])
			if err != nil {
				return nil, fmt.Errorf("error during instanciation of %s: %v", middlewareName, err)
			}
			return constructor(next)
		})
	}
	return &chain
}
1016040
func makeHeaderChain(parent *types.Header, n int, engine consensus.Engine, db ethdb.Database, seed int) []*types.Header {
	blocks := makeBlockChain(types.NewBlockWithHeader(parent), n, engine, db, seed)
	headers := make([]*types.Header, len(blocks))
	for i, block := range blocks {
		headers[i] = block.Header()
	}
	return headers
}
363837
func (server *Server) SendChain(chain *tasks.Chain) (*result.ChainAsyncResult, error) {
	_, err := server.SendTask(chain.Tasks[0])
	if err != nil {
		return nil, err
	}

	return result.NewChainAsyncResult(chain.Tasks, server.backend), nil
}
850208
func NewToken(userID string, key string, method string, action string, timestamp time.Time) string {
	fmtTime := timestamp.Format("20060102T150405Z")
	logrus.Debugf("Built timestamp: %s", fmtTime)

	message := strings.Join([]string{method, action, fmtTime}, "")
	logrus.Debugf("Built message: %s", message)

	signatureHmac := hmac.New(sha256.New, []byte(key))

	signatureHmac.Write([]byte(message))

	signature := base64.StdEncoding.EncodeToString([]byte(signatureHmac.Sum(nil)))
	logrus.Debugf("Built signature: %s", signature)

	userIDAndSignature := fmt.Sprintf("%s:%s", userID, signature)

	token := base64.StdEncoding.EncodeToString([]byte(userIDAndSignature))
	logrus.Debugf("Built token: %s", token)

	return token
}
771993
func NewChainAsyncResult(tasks []*tasks.Signature, backend iface.Backend) *ChainAsyncResult {
	asyncResults := make([]*AsyncResult, len(tasks))
	for i, task := range tasks {
		asyncResults[i] = NewAsyncResult(task, backend)
	}
	return &ChainAsyncResult{
		asyncResults: asyncResults,
		backend:      backend,
	}
}
618355
func NewTaskQueue(syncFn func(string) error) *taskQueue {
	return &taskQueue{
		queue:      workqueue.NewRateLimitingQueue(workqueue.DefaultControllerRateLimiter()),
		sync:       syncFn,
		workerDone: make(chan struct{}),
	}
}
161102
func NewTask(lifecycle Lifecycle, payload []byte) *Task {
	return &Task{lifecycle: lifecycle, payload: payload}
}
1064229
func (c *Client) workOnTask(t task) {
	switch t.Action {
	case subscribeAction:
		event := t.Listener.Event
		// Check to see if it already exists in the subscribed map.
		// If not, then we need to create a new listener list and
		// start listening on the pubsub client. Otherwise just
		// append it.
		if _, exists := c.subscribed[event]; !exists || t.Force {
			c.subscribed[event] = []*Listener{t.Listener}
			switch t.Listener.Type {
			case Channel:
				c.pubsub.Subscribe(event)
			case Pattern:
				c.pubsub.PSubscribe(event)
			}
		} else {
			c.subscribed[event] = append(c.subscribed[event], t.Listener)
		}
	case unsubscribeAction:
		event := t.Listener.Event
		// Look for the listener in the subscribed list and,
		// once found, remove it.
		list := c.subscribed[event]
		for i, l := range list {
			if l == t.Listener {
				c.subscribed[event] = append(list[:i], list[i+1:]...)
				break
			}
		}

		// If the list is now empty, we can unsubscribe on Redis and
		// remove it from our registery
		if len(c.subscribed[event]) == 0 || t.Force {
			switch t.Listener.Type {
			case Channel:
				c.pubsub.Unsubscribe(event)
			case Pattern:
				c.pubsub.PUnsubscribe(event)
			}
			delete(c.subscribed, event)
		}
	case disruptAction:
		c.pubsub.Conn.Close()
	default:
		panic("unknown task")
	}
}
809362
func NewTrackEngine(g *libkb.GlobalContext, arg *TrackEngineArg) *TrackEngine {
	return &TrackEngine{
		arg:          arg,
		Contextified: libkb.NewContextified(g),
	}
}
561628
func newTokenBucket(rate *rate, clock timetools.TimeProvider) *tokenBucket {
	return &tokenBucket{
		period:          rate.period,
		timePerToken:    time.Duration(int64(rate.period) / rate.average),
		burst:           rate.burst,
		clock:           clock,
		lastRefresh:     clock.UtcNow(),
		availableTokens: rate.burst,
	}
}
693778
func NewChain(signatures ...*Signature) (*Chain, error) {
	// Auto generate task UUIDs if needed
	for _, signature := range signatures {
		if signature.UUID == "" {
			signatureID := uuid.New().String()
			signature.UUID = fmt.Sprintf("task_%v", signatureID)
		}
	}

	for i := len(signatures) - 1; i > 0; i-- {
		if i > 0 {
			signatures[i-1].OnSuccess = []*Signature{signatures[i]}
		}
	}

	chain := &Chain{Tasks: signatures}

	return chain, nil
}