// Run runs the ticker.
165566
func (t *Ticker) Run() {
	var (
		i, priorPos, pos, line, fieldNum int
		n                                uint64
		v                                byte
		err                              error
		dev                              structs.Device
		cur                              structs.DiskStats
	)
	// ticker
	for {
		select {
		case <-t.Done:
			return
		case <-t.C:
			cur.Timestamp = time.Now().UTC().UnixNano()
			err = t.Reset()
			if err != nil {
				t.Errs <- err
				break
			}
			cur.Device = cur.Device[:0]
			// read each line until eof
			for {
				t.Val = t.Val[:0]
				t.Line, err = t.ReadSlice('\n')
				if err != nil {
					if err == io.EOF {
						break
					}
					t.Errs <- &joe.ReadError{Err: err}
					break
				}
				line++
				pos = 0
				fieldNum = 0
				// process the fields in the line
				for {
					// ignore spaces on the first two fields
					if fieldNum < 2 {
						for i, v = range t.Line[pos:] {
							if v != 0x20 {
								break
							}
						}
						pos += i
					}
					fieldNum++
					for i, v = range t.Line[pos:] {
						if v == 0x20 || v == '\n' {
							break
						}
					}
					if fieldNum != 3 {
						n, err = helpers.ParseUint(t.Line[pos : pos+i])
						if err != nil {
							t.Errs <- &joe.ParseError{Info: fmt.Sprintf("line %d: field %d", line, fieldNum), Err: err}
							continue
						}
					}
					priorPos, pos = pos, pos+i+1
					if fieldNum < 8 {
						if fieldNum < 4 {
							if fieldNum < 2 {
								if fieldNum == 1 {
									dev.Major = uint32(n)
									continue
								}
								dev.Minor = uint32(n)
								continue
							}
							dev.Name = string(t.Line[priorPos:pos])
							continue
						}
						if fieldNum < 6 {
							if fieldNum == 4 {
								dev.ReadsCompleted = n
								continue
							}
							dev.ReadsMerged = n
							continue
						}
						if fieldNum == 6 {
							dev.ReadSectors = n
							continue
						}
						dev.ReadingTime = n
						continue
					}
					if fieldNum < 12 {
						if fieldNum < 10 {
							if fieldNum == 8 {
								dev.WritesCompleted = n
								continue
							}
							dev.WritesMerged = n
							continue
						}
						if fieldNum == 10 {
							dev.WrittenSectors = n
							continue
						}
						dev.WritingTime = n
						continue
					}
					if fieldNum == 12 {
						dev.IOInProgress = int32(n)
						continue
					}
					if fieldNum == 13 {
						dev.IOTime = n
						continue
					}
					dev.WeightedIOTime = n
					break
				}
				cur.Device = append(cur.Device, dev)
			}
			t.Data <- t.CalculateUsage(&cur)
			// set prior info
			t.prior.Timestamp = cur.Timestamp
			if len(t.prior.Device) != len(cur.Device) {
				t.prior.Device = make([]structs.Device, len(cur.Device))
			}
			copy(t.prior.Device, cur.Device)
		}
	}
}
843327
func (s *Simple) run() {
	for {
		select {
		case <-time.After(s.config.GCPeriodicity):
			s.GC()
		case <-s.halt:
			s.closeError <- nil
			// there is no cleanup required, so we just return
			return
		}
	}
}
432758
func (m *RollbackManager) run() {
	m.logger.Info("starting rollback manager")
	tick := time.NewTicker(m.period)
	defer tick.Stop()
	defer close(m.doneCh)
	for {
		select {
		case <-tick.C:
			m.triggerRollbacks()

		case <-m.shutdownCh:
			m.logger.Info("stopping rollback manager")
			return
		}
	}
}
345805
func (b *Bridge) Run(ctx context.Context) {
	ticker := time.NewTicker(b.interval)
	defer ticker.Stop()
	for {
		select {
		case <-ticker.C:
			if err := b.Push(); err != nil && b.logger != nil {
				b.logger.Println("error pushing to Graphite:", err)
			}
		case <-ctx.Done():
			return
		}
	}
}
371131
func (config *Config) Run(cmd string) (string, error) {
	if config.DisplayOutput == true {
		fmt.Printf("run: %s\n", cmd)
	}
	return config.doRun(cmd, false)
}
400120
func (a *Autopilot) run() {
	defer a.waitGroup.Done()

	// Monitor server health until shutdown
	ticker := time.NewTicker(a.interval)
	defer ticker.Stop()

	for {
		select {
		case <-a.shutdownCh:
			return
		case <-ticker.C:
			if err := a.promoteServers(); err != nil {
				a.logger.Printf("[ERR] autopilot: Error promoting servers: %v", err)
			}

			if err := a.pruneDeadServers(); err != nil {
				a.logger.Printf("[ERR] autopilot: Error checking for dead servers to remove: %s", err)
			}
		case <-a.removeDeadCh:
			if err := a.pruneDeadServers(); err != nil {
				a.logger.Printf("[ERR] autopilot: Error checking for dead servers to remove: %s", err)
			}
		}
	}
}
946110
func (t *Ticker) Run() {
	var (
		i, pos, line, fieldNum int
		n                      uint64
		v                      byte
		err                    error
		cur                    structs.DevInfo
		dev                 structs.Device
	)
	// ticker
	for {
		select {
		case <-t.Done:
			return
		case <-t.C:
			cur.Timestamp = time.Now().UTC().UnixNano()
			err = t.Reset()
			if err != nil {
				t.Errs <- err
				break
			}
			line = 0
			cur.Device = cur.Device[:0]
			// read each line until eof
			for {
				t.Val = t.Val[:0]
				t.Line, err = t.ReadSlice('\n')
				if err != nil {
					if err == io.EOF {
						break
					}
					t.Errs <- &joe.ReadError{Err: err}
					break
				}
				line++
				if line < 3 {
					continue
				}
				// first grab the interface name (everything up to the ':')
				for i, v = range t.Line {
					if v == 0x3A {
						pos = i + 1
						break
					}
					// skip spaces
					if v != 0x20 {
						continue
					}
					t.Val = append(t.Val, v)
				}
				dev.Name = string(t.Val[:])
				fieldNum = 0
				// process the rest of the line
				for {
					fieldNum++
					// skip all spaces
					for i, v = range t.Line[pos:] {
						if v != 0x20 {
							pos += i
							break
						}
					}
					// grab the numbers
					for i, v = range t.Line[pos:] {
						if v == 0x20 || v == '\n' {
							break
						}
					}
					// any conversion error results in 0
					n, err = helpers.ParseUint(t.Line[pos : pos+1])
					pos += i
					if err != nil {
						t.Errs <- &joe.ParseError{Info: fmt.Sprintf("line %d: field %d", line, fieldNum), Err: err}
						continue
					}
					if fieldNum < 9 {
						if fieldNum < 5 {
							if fieldNum < 3 {
								if fieldNum == 1 {
									dev.RBytes = int64(n)
									continue
								}
								dev.RPackets = int64(n) // must be 2
								continue
							}
							if fieldNum == 3 {
								dev.RErrs = int64(n)
								continue
							}
							dev.RDrop = int64(n) // must be 4
							continue
						}
						if fieldNum < 7 {
							if fieldNum == 5 {
								dev.RFIFO = int64(n)
								continue
							}
							dev.RFrame = int64(n) // must be 6
							continue
						}
						if fieldNum == 7 {
							dev.RCompressed = int64(n)
							continue
						}
						dev.RMulticast = int64(n) // must be 8
						continue
					}
					if fieldNum < 13 {
						if fieldNum < 11 {
							if fieldNum == 9 {
								dev.TBytes = int64(n)
								continue
							}
							dev.TPackets = int64(n) // must be 10
							continue
						}
						if fieldNum == 11 {
							dev.TErrs = int64(n)
							continue
						}
						dev.TDrop = int64(n) // must be 12
						continue
					}
					if fieldNum < 15 {
						if fieldNum == 13 {
							dev.TFIFO = int64(n)
							continue
						}
						dev.TColls = int64(n) // must be 14
						continue
					}
					if fieldNum == 15 {
						dev.TCarrier = int64(n)
						continue
					}
					if fieldNum == 16 {
						dev.TCompressed = int64(n)
						break
					}
				}
				cur.Device = append(cur.Device, dev)
			}
			t.Data <- t.CalculateUsage(&cur)
			t.prior.Timestamp = cur.Timestamp
			if len(t.prior.Device) != len(cur.Device) {
				t.prior.Device = make([]structs.Device, len(cur.Device))
			}
			copy(t.prior.Device, cur.Device)
		}
	}
}
19354
func (pget *Pget) Run() error {
	if err := pget.Ready(); err != nil {
		return pget.ErrTop(err)
	}

	if err := pget.Checking(); err != nil {
		return errors.Wrap(err, "failed to check header")
	}

	if err := pget.Download(); err != nil {
		return err
	}

	if err := pget.Utils.BindwithFiles(pget.Procs); err != nil {
		return err
	}

	return nil
}
270119
func (u *DropsondeUnmarshaller) Run(inputChan <-chan []byte, outputChan chan<- *events.Envelope) {
	for message := range inputChan {
		envelope, err := u.UnmarshallMessage(message)
		if err != nil {
			continue
		}
		outputChan <- envelope
	}
}
1274708
func (m Monitor) Run(check Check, ch chan MonitorEvent) stream.Stream {
	if m.StartInterval == 0 {
		m.StartInterval = defaultStartInterval
	}
	if m.Interval == 0 {
		m.Interval = defaultInterval
	}
	if m.Threshold == 0 {
		m.Threshold = defaultThreshold
	}

	stream := stream.New()
	go func() {
		t := time.NewTicker(m.StartInterval)
		defer close(ch)

		status := MonitorStatusCreated
		var upCount, downCount int
		up := func() {
			downCount = 0
			upCount++
			if status == MonitorStatusCreated || status == MonitorStatusDown && upCount >= m.Threshold {
				if status == MonitorStatusCreated {
					t.Stop()
					t = time.NewTicker(m.Interval)
				}
				status = MonitorStatusUp
				if m.Logger != nil {
					m.Logger.Info("new monitor status", "status", status, "check", check)
				}
				select {
				case ch <- MonitorEvent{
					Status: status,
					Check:  check,
				}:
				case <-stream.StopCh:
				}
			}
		}
		down := func(err error) {
			upCount = 0
			downCount++
			if m.Logger != nil {
				m.Logger.Warn("healthcheck error", "check", check, "err", err)
			}
			if status == MonitorStatusUp && downCount >= m.Threshold {
				status = MonitorStatusDown
				if m.Logger != nil {
					m.Logger.Info("new monitor status", "status", status, "check", check, "err", err)
				}
				select {
				case ch <- MonitorEvent{
					Status: status,
					Err:    err,
					Check:  check,
				}:
				case <-stream.StopCh:
				}
			}
		}
		check := func() {
			if err := check.Check(); err != nil {
				down(err)
			} else {
				up()
			}
		}

		check()
	outer:
		for {
			select {
			case <-t.C:
				check()
			case <-stream.StopCh:
				break outer
			}
		}
		t.Stop()
	}()

	return stream
}
291069
func (h HookFunc) Run(e *Event, level Level, message string) {
	h(e, level, message)
}
703567
func (c *monitoredCmd) run(ctx context.Context) error {
	// Check for cancellation before even starting
	if ctx.Err() != nil {
		return ctx.Err()
	}

	ticker := time.NewTicker(c.timeout)
	done := make(chan error, 1)
	defer ticker.Stop()

	err := c.cmd.Start()
	if err != nil {
		return err
	}

	go func() {
		done <- c.cmd.Wait()
	}()

	for {
		select {
		case <-ticker.C:
			if c.hasTimedOut() {
				if err := c.cmd.Process.Kill(); err != nil {
					return &killCmdError{err}
				}

				return &timeoutError{c.timeout}
			}
		case <-ctx.Done():
			if err := c.cmd.Process.Kill(); err != nil {
				return &killCmdError{err}
			}
			return ctx.Err()
		case err := <-done:
			return err
		}
	}
}
1360324
func (mod *SocketBee) Run(cin chan bees.Event) {
	mod.eventChan = cin

	select {
	case <-mod.SigChan:
		return
	}
}
314815
func (mod *HTTPBee) Run(cin chan bees.Event) {
	mod.eventChan = cin

	select {
	case <-mod.SigChan:
		return
	}
}
452627
func (s *StreamFramer) Run() {
	s.l.Lock()
	defer s.l.Unlock()
	if s.running {
		return
	}

	s.running = true
	go s.run()
}
1311856
func (c *Complete) Run() bool {
	c.AddFlags(nil)
	flag.Parse()
	return c.Complete()
}
555847
func (t *Ticker) Run() {
	// predeclare some vars
	var (
		i, pos, nameLen int
		v               byte
		n               uint64
		err             error
		inf             Info
	)
	// ticker
	for {
		select {
		case <-t.Done:
			return
		case <-t.C:
			err = t.Profiler.Reset()
			if err != nil {
				t.Errs <- err
				continue
			}
			inf.Timestamp = time.Now().UTC().UnixNano()
			for {
				t.Val = t.Val[:0]
				t.Line, err = t.ReadSlice('\n')
				if err != nil {
					if err == io.EOF {
						break
					}
					t.Errs <- &joe.ReadError{Err: err}
				}
				// first grab the key name (everything up to the ':')
				for i, v = range t.Line {
					if v == ':' {
						pos = i + 1
						break
					}
					t.Val = append(t.Val, v)
				}
				nameLen = len(t.Val)

				// skip all spaces
				for i, v = range t.Line[pos:] {
					if v != ' ' {
						pos += i
						break
					}
				}

				// grab the numbers
				for _, v = range t.Line[pos:] {
					if v == ' ' || v == '\n' {
						break
					}
					t.Val = append(t.Val, v)
				}
				// any conversion error results in 0
				n, err = helpers.ParseUint(t.Val[nameLen:])
				if err != nil {
					t.Errs <- &joe.ParseError{Info: string(t.Val[:nameLen]), Err: err}
				}

				v = t.Val[0]
				// evaluate the key
				if v == 'A' {
					if t.Val[5] == 'e' {
						if nameLen == 6 {
							inf.Active = n
							continue
						}
						if t.Val[7] == 'a' {
							inf.ActiveAnon = n
							continue
						}
						inf.ActiveFile = n
						continue
					}
					if nameLen == 9 {
						inf.AnonPages = n
						continue
					}
					inf.AnonHugePages = n
					continue
				}
				if v == 'C' {
					if nameLen == 6 {
						inf.Cached = n
						continue
					}
					if nameLen == 11 {
						inf.CommitLimit = n
						continue
					}
					inf.CommittedAS = n
					continue
				}
				if v == 'D' {
					if nameLen == 5 {
						inf.Dirty = n
						continue
					}
					if t.Val[10] == 'k' {
						inf.DirectMap4K = n
						continue
					}
					inf.DirectMap2M = n
					continue
				}
				if v == 'H' {
					if nameLen == 14 {
						if t.Val[10] == 'F' {
							inf.HugePagesFree = n
							continue
						}
						if t.Val[10] == 'R' {
							inf.HugePagesRsvd = n
							continue
						}
						inf.HugePagesSurp = n
					}
					if t.Val[1] == 'a' {
						inf.HardwareCorrupted = n
						continue
					}
					if t.Val[9] == 'i' {
						inf.HugePagesSize = n
						continue
					}
					inf.HugePagesTotal = n
					continue
				}
				if v == 'I' {
					if nameLen == 8 {
						inf.Inactive = n
						continue
					}
					if t.Val[9] == 'a' {
						inf.InactiveAnon = n
						continue
					}
					inf.InactiveFile = n
				}
				if v == 'M' {
					v = t.Val[3]
					if nameLen < 8 {
						if v == 'p' {
							inf.Mapped = n
							continue
						}
						if v == 'F' {
							inf.MemFree = n
							continue
						}
						inf.Mlocked = n
						continue
					}
					if v == 'A' {
						inf.MemAvailable = n
						continue
					}
					inf.MemTotal = n
					continue
				}
				if v == 'S' {
					v = t.Val[1]
					if v == 'w' {
						if t.Val[4] == 'C' {
							inf.SwapCached = n
							continue
						}
						if t.Val[4] == 'F' {
							inf.SwapFree = n
							continue
						}
						inf.SwapTotal = n
						continue
					}
					if v == 'h' {
						inf.Shmem = n
						continue
					}
					if v == 'l' {
						inf.Slab = n
						continue
					}
					if v == 'R' {
						inf.SReclaimable = n
						continue
					}
					inf.SUnreclaim = n
					continue
				}
				if v == 'V' {
					if t.Val[8] == 'C' {
						inf.VmallocChunk = n
						continue
					}
					if t.Val[8] == 'T' {
						inf.VmallocTotal = n
						continue
					}
					inf.VmallocUsed = n
					continue
				}
				if v == 'W' {
					if nameLen == 9 {
						inf.Writeback = n
						continue
					}
					inf.WritebackTmp = n
					continue
				}
				if v == 'B' {
					if nameLen == 6 {
						inf.Bounce = n
						continue
					}
					inf.Buffers = n
					continue
				}
				if v == 'K' {
					inf.KernelStack = n
					continue
				}
				if v == 'N' {
					inf.NFSUnstable = n
					continue
				}
				if v == 'P' {
					inf.PageTables = n
				}
				inf.Unevictable = n
			}
			t.Data <- inf
		}
	}
}