// NewSentryHook creates a hook to be added to an instance of logger
// and initializes the raven client.
// This method sets the timeout to 100 milliseconds.
197685
func NewSentryHook(DSN string, levels []logrus.Level) (*SentryHook, error) {
	client, err := raven.New(DSN)
	if err != nil {
		return nil, err
	}
	return NewWithClientSentryHook(client, levels)
}
373062
func handleHook(a HookAction, err error) {
	if err != nil {
		// TODO: handle errors
	}

	switch a {
	case HookActionContinue:
		return
	case HookActionHalt:
		panic(HookActionHalt)
	}
}
1372564
func (s *Service) AddLogEntry(ctx context.Context, k, v []byte, t time.Time) error {
	return s.kv.Update(ctx, func(tx Tx) error {
		return s.addLogEntry(ctx, tx, k, v, t)
	})
}
324920
func NewElasticHook(client *elastic.Client, host string, level logrus.Level, index string) (*ElasticHook, error) {
	return NewElasticHookWithFunc(client, host, level, func() string { return index })
}
1114790
func callWorkflowHook(hookPhase string,
	hook WorkflowHook,
	hooks []WorkflowHookHandler,
	ctx *workflowContext) error {

	if hook != nil {
		ctx.logger.Warn(fmt.Sprintf("DEPRECATED: Single %s hook superseded by %ss slice",
			hookPhase,
			hookPhase))
		hooks = append(hooks, WorkflowHookFunc(hook))
	}
	for _, eachHook := range hooks {
		// Run the hook
		ctx.logger.WithFields(logrus.Fields{
			"Phase":               hookPhase,
			"WorkflowHookContext": ctx.context.workflowHooksContext,
		}).Info("Calling WorkflowHook")

		hookErr := eachHook.DecorateWorkflow(ctx.context.workflowHooksContext,
			ctx.userdata.serviceName,
			ctx.userdata.s3Bucket,
			ctx.userdata.buildID,
			ctx.context.awsSession,
			ctx.userdata.noop,
			ctx.logger)
		if hookErr != nil {
			return errors.Wrapf(hookErr, "DecorateWorkflow returned an error")
		}
	}
	return nil
}
31760
func NewHook(source, hook io.Reader) io.Reader {
	if hook == nil {
		return source
	}
	return &hookReader{source, hook}
}
531163
func NewHook(name string, params []string) *Hook {
	return &Hook{Name: name, Parameters: params}
}
635358
func (d *stateFile) CommitHook(hi hook.Info) (err error) {
	defer errors.DeferredAnnotatef(&err, "failed to write %q hook info for %q on state directory", hi.Kind, hi.StorageId)
	if hi.Kind == hooks.StorageDetaching {
		return d.Remove()
	}
	attached := true
	di := diskInfo{&attached}
	if err := utils.WriteYaml(d.path, &di); err != nil {
		return err
	}
	// If write was successful, update own state.
	d.state.attached = true
	return nil
}
299782
func (s *OrganizationsService) CreateHook(ctx context.Context, org string, hook *Hook) (*Hook, *Response, error) {
	u := fmt.Sprintf("orgs/%v/hooks", org)

	hookReq := &createHookRequest{
		Name:   "web",
		Events: hook.Events,
		Active: hook.Active,
		Config: hook.Config,
	}

	req, err := s.client.NewRequest("POST", u, hookReq)
	if err != nil {
		return nil, nil, err
	}

	h := new(Hook)
	resp, err := s.client.Do(ctx, req, h)
	if err != nil {
		return nil, resp, err
	}

	return h, resp, nil
}
168009
func (s *Server) RegisterEOFHook(h EOFHook) error {
	return s.xp.dispatcher.RegisterEOFHook(h)
}
239765
func (m *MockFactory) NewRunHook(arg0 hook.Info) (operation.Operation, error) {
	ret := m.ctrl.Call(m, "NewRunHook", arg0)
	ret0, _ := ret[0].(operation.Operation)
	ret1, _ := ret[1].(error)
	return ret0, ret1
}
1077537
func (db *baseDB) AddQueryHook(hook QueryHook) {
	db.queryHooks = append(db.queryHooks, hook)
}
739873
func (dt *dynamicTimeout) logEntry(duration time.Duration) {
	entries := int(atomic.AddInt64(&dt.entries, 1))
	index := entries - 1
	if index < dynamicTimeoutLogSize {
		dt.mutex.Lock()
		dt.log[index] = duration
		dt.mutex.Unlock()
	}
	if entries == dynamicTimeoutLogSize {
		dt.mutex.Lock()

		// Make copy on stack in order to call adjust()
		logCopy := [dynamicTimeoutLogSize]time.Duration{}
		copy(logCopy[:], dt.log[:])

		// reset log entries
		atomic.StoreInt64(&dt.entries, 0)

		dt.mutex.Unlock()

		dt.adjust(logCopy)
	}
}
613830
func customDecodeHook() mapstructure.DecodeHookFunc {
	durationHook := mapstructure.StringToTimeDurationHookFunc()
	return func(f reflect.Type, t reflect.Type, data interface{}) (interface{}, error) {
		dur, err := mapstructure.DecodeHookExec(durationHook, f, t, data)
		if err == nil {
			if _, ok := dur.(time.Duration); ok {
				return dur, nil
			}
		}

		if f.Kind() != reflect.String {
			return data, nil
		}

		raw := data.(string)
		l := len(raw)
		if l > 1 && raw[0] == '[' && raw[l-1] == ']' {
			slice := strings.Split(raw[1:l-1], ",")
			for i, v := range slice {
				slice[i] = strings.TrimSpace(v)
			}
			return slice, nil
		}

		return data, nil
	}
}
922958
func (rh *runHook) afterHook(state State) (_ bool, err error) {
	defer func() {
		if err != nil {
			logger.Errorf("error updating workload status after %v hook: %v", rh.info.Kind, err)
		}
	}()

	ctx := rh.runner.Context()
	hasRunStatusSet := ctx.HasExecutionSetUnitStatus() || state.StatusSet
	switch rh.info.Kind {
	case hooks.Stop:
		// Charm is no longer of this world.
		err = ctx.SetUnitStatus(jujuc.StatusInfo{
			Status: string(status.Terminated),
		})
	case hooks.Start:
		if hasRunStatusSet {
			break
		}
		logger.Debugf("unit %v has started but has not yet set status", ctx.UnitName())
		// We've finished the start hook and the charm has not updated its
		// own status so we'll set it to unknown.
		err = ctx.SetUnitStatus(jujuc.StatusInfo{
			Status: string(status.Unknown),
		})
	case hooks.RelationBroken:
		var isLeader bool
		isLeader, err = ctx.IsLeader()
		if !isLeader || err != nil {
			return hasRunStatusSet && err == nil, err
		}
		rel, rErr := ctx.Relation(rh.info.RelationId)
		if rErr == nil && rel.Suspended() {
			err = rel.SetStatus(relation.Suspended)
		}
	}
	return hasRunStatusSet && err == nil, err
}
1345340
func NewSentryRecoveryWare(client *raven.Client, flags ...bool) Middleware {
	stackFlags := []bool{false, false}
	for i := range flags {
		if i >= len(stackFlags) {
			break
		}
		stackFlags[i] = flags[i]
	}
	return &SentryRecoveryWare{
		client:     client,
		printStack: stackFlags[0],
		stackAll:   stackFlags[1],
		stackSize:  1024 * 8,
	}
}
1051827
func newHook(source, hook io.Reader) io.Reader {
	if hook == nil {
		return source
	}
	return &hookReader{source, hook}
}