// ************************ UTILITY HANDLERS ************************************
// Scrub all the Intervals and IntervalActions
487967
func scrubAllHandler(w http.ResponseWriter, r *http.Request) {
	defer r.Body.Close()

	switch r.Method {
	case http.MethodDelete:
		count, err := scrubAll()
		if err != nil {
			http.Error(w, err.Error(), http.StatusInternalServerError)
			return
		}
		w.Header().Set("Content-Type", "application/json")
		w.WriteHeader(http.StatusOK)
		w.Write([]byte(strconv.Itoa(count)))
	}
}
83038
func (_m *DBClient) IntervalActionById(id string) (models.IntervalAction, error) {
	ret := _m.Called(id)

	var r0 models.IntervalAction
	if rf, ok := ret.Get(0).(func(string) models.IntervalAction); ok {
		r0 = rf(id)
	} else {
		r0 = ret.Get(0).(models.IntervalAction)
	}

	var r1 error
	if rf, ok := ret.Get(1).(func(string) error); ok {
		r1 = rf(id)
	} else {
		r1 = ret.Error(1)
	}

	return r0, r1
}
322319
func (r *PrevRevisions) Cleanup() {
	r.mu.Lock()
	defer r.mu.Unlock()

	r.revisions = make(map[string]datasync.KeyVal)
}
1037838
func (mc MongoClient) ScrubAllEvents() error {
	s := mc.getSessionCopy()
	defer s.Close()

	_, err := s.DB(mc.database.Name).C(db.ReadingsCollection).RemoveAll(nil)
	if err != nil {
		return errorMap(err)
	}

	_, err = s.DB(mc.database.Name).C(db.EventsCollection).RemoveAll(nil)
	if err != nil {
		return errorMap(err)
	}

	return nil
}
902951
func (_m *SchedulerQueueClient) QueryIntervalActionByName(intervalActionName string) (models.IntervalAction, error) {
	ret := _m.Called(intervalActionName)

	var r0 models.IntervalAction
	if rf, ok := ret.Get(0).(func(string) models.IntervalAction); ok {
		r0 = rf(intervalActionName)
	} else {
		r0 = ret.Get(0).(models.IntervalAction)
	}

	var r1 error
	if rf, ok := ret.Get(1).(func(string) error); ok {
		r1 = rf(intervalActionName)
	} else {
		r1 = ret.Error(1)
	}

	return r0, r1
}
1361862
func Scrub(str, repl string) string {
	var buf *bytes.Buffer
	var r rune
	var size, pos int
	var hasError bool

	origin := str

	for len(str) > 0 {
		r, size = utf8.DecodeRuneInString(str)

		if r == utf8.RuneError {
			if !hasError {
				if buf == nil {
					buf = &bytes.Buffer{}
				}

				buf.WriteString(origin[:pos])
				hasError = true
			}
		} else if hasError {
			hasError = false
			buf.WriteString(repl)

			origin = origin[pos:]
			pos = 0
		}

		pos += size
		str = str[size:]
	}

	if buf != nil {
		buf.WriteString(origin)
		return buf.String()
	}

	// No invalid byte.
	return origin
}
434586
func (cache *Cache) pruneInterval() time.Duration {
	if cache.AccessUpdateInterval > 0 && cache.PruneFactor > 0 {
		return cache.AccessUpdateInterval * time.Duration(1+cache.PruneFactor)
	}
	return 0
}
671064
func (ivs *Intervals) Dispose() {
	for i := 0; i < len(*ivs); i++ {
		(*ivs)[i] = nil
	}

	*ivs = (*ivs)[:0]
	intervalsPool.Put(*ivs)
}
379138
func (proxier *Proxier) cleanupStaleStickySessions() {
	for name := range proxier.serviceMap {
		proxier.loadBalancer.CleanupStaleStickySessions(name)
	}
}
385984
func (c *Consumer) maintainCleanCoordinator() {
	if c.stopCleanup != nil {
		return
	}

	c.stopCleanup = make(chan struct{})
	go func() {
		tick := time.NewTicker(5 * time.Minute)
		defer tick.Stop()
		for {
			select {
			case <-tick.C:
				Infof(c, "Starting coordinator cleanup of API requests for %s", c.config.Groupid)
				c.config.Coordinator.RemoveOldApiRequests(c.config.Groupid)
			case <-c.stopCleanup:
				return
			}
		}
	}()
}
658670
func FlushInterval(interval time.Duration) Option {
	return func(c *client) {
		c.flushInterval = interval
	}
}
1158637
func (_m *DBClient) IntervalActionByName(name string) (models.IntervalAction, error) {
	ret := _m.Called(name)

	var r0 models.IntervalAction
	if rf, ok := ret.Get(0).(func(string) models.IntervalAction); ok {
		r0 = rf(name)
	} else {
		r0 = ret.Get(0).(models.IntervalAction)
	}

	var r1 error
	if rf, ok := ret.Get(1).(func(string) error); ok {
		r1 = rf(name)
	} else {
		r1 = ret.Error(1)
	}

	return r0, r1
}
207311
func (st *Store) Cleanup() {
	st.db.Delete(&gormSession{tableName: st.opts.TableName}, "expires_at <= ?", gorm.NowFunc())
}
462334
func (_m *DBClient) IntervalActionsWithLimit(limit int) ([]models.IntervalAction, error) {
	ret := _m.Called(limit)

	var r0 []models.IntervalAction
	if rf, ok := ret.Get(0).(func(int) []models.IntervalAction); ok {
		r0 = rf(limit)
	} else {
		if ret.Get(0) != nil {
			r0 = ret.Get(0).([]models.IntervalAction)
		}
	}

	var r1 error
	if rf, ok := ret.Get(1).(func(int) error); ok {
		r1 = rf(limit)
	} else {
		r1 = ret.Error(1)
	}

	return r0, r1
}
200047
func (mc MongoClient) AddIntervalAction(action contract.IntervalAction) (string, error) {
	s := mc.getSessionCopy()
	defer s.Close()

	var mapped models.IntervalAction
	id, err := mapped.FromContract(action)
	if err != nil {
		return "", err
	}

	// See if the name is unique and add the value descriptors
	found, err := s.DB(mc.database.Name).C(db.IntervalAction).Find(bson.M{"name": mapped.Name}).Count()
	// Duplicate name
	if found > 0 {
		return "", db.ErrNotUnique
	}

	mapped.TimestampForAdd()

	if err = s.DB(mc.database.Name).C(db.IntervalAction).Insert(mapped); err != nil {
		return "", errorMap(err)
	}
	return id, nil
}
209557
func (c *Client) DeleteIntervalActionById(id string) (err error) {
	check, err := c.IntervalActionById(id)
	if err != nil {
		if err == db.ErrNotFound {
			return nil
		}
		return
	}

	action := models.NewIntervalAction(check)
	conn := c.Pool.Get()
	defer conn.Close()

	_ = conn.Send("MULTI")
	deleteObject(action, id, conn)

	_, err = conn.Do("EXEC")

	return err
}
1189690
func (m *MultiSelect) Cleanup(val interface{}) error {
	// execute the output summary template with the answer
	return m.Render(
		MultiSelectQuestionTemplate,
		MultiSelectTemplateData{
			MultiSelect:   *m,
			SelectedIndex: m.selectedIndex,
			Checked:       m.checked,
			Answer:        strings.Join(val.([]string), ", "),
			ShowAnswer:    true,
		},
	)
}