// startFromWorking attempts to create a run if one is due, and then begins execution on a separate goroutine.
// r.state must be runnerWorking when this is called.
198817
func (r *runner) startFromWorking(now int64) {
	if nextDue, hasQueue := r.ts.NextDue(); now < nextDue && !hasQueue {
		// Not ready for a new run. Go idle again.
		atomic.StoreUint32(r.state, runnerIdle)
		return
	}
	ctx, cancel := context.WithCancel(r.ctx)
	rc, err := r.desiredState.CreateNextRun(ctx, r.task.ID, now)
	if err != nil {
		r.logger.Info("Failed to create run", zap.Error(err))
		atomic.StoreUint32(r.state, runnerIdle)
		cancel() // cancel to prevent context leak
		return
	}
	qr := rc.Created
	r.ts.runningMu.Lock()
	r.ts.running[qr.RunID] = runCtx{Context: ctx, CancelFunc: cancel}
	r.ts.runningMu.Unlock()
	r.ts.SetNextDue(rc.NextDue, rc.HasQueue, qr.Now)

	// Create a new child logger for the individual run.
	// We can't do r.logger = r.logger.With(zap.String("run_id", qr.RunID.String()) because zap doesn't deduplicate fields,
	// and we'll quickly end up with many run_ids associated with the log.
	runLogger := r.logger.With(zap.String("run_id", qr.RunID.String()), zap.Int64("now", qr.Now))

	runLogger.Info("Created run; beginning execution")
	r.wg.Add(1)
	go r.executeAndWait(ctx, qr, runLogger)

	r.updateRunState(qr, RunStarted, runLogger)
}
351642
func (s *Service) start() {
	for _, m := range s.modules {
		n := getModuleName(m)
		c := s.configs[n]
		BootPrintln("[service] starting", n)
		if c.Start != nil {
			c.Start()
		}
	}
	// mark as started
	s.started.Done()

	// mark process as running
	s.running.Add(1)

	// wait for a stop signal to be received
	// note: that c might crash without this parent goroutine knowing.
	s.wait()

	// mark process as done
	s.running.Done()
}
1057680
func (c *TasksCountCall) Start(start float64) *TasksCountCall {
	c.urlParams_.Set("start", fmt.Sprint(start))
	return c
}
857888
func (w worker) start() {
	logger := w.logger.WithFields(log.Fields{"_block": "start"})
	// task worker
	w.waitGroup.Add(1)
	go func() {
		defer w.waitGroup.Done()
		logger.Debug("starting task worker")
		for {
			select {
			case work := <-w.taskWork:
				// Receive a work request.
				logger := w.logger.WithFields(log.Fields{
					"task":         work.Task.ID,
					"request-type": work.RequestType.String(),
					"retries":      work.retryCount,
				})
				logger.Debug("received task work")
				if work.RequestType == TaskStartedType {
					if err := w.startTask(work.Task.ID); err != nil {
						if work.retryCount < retryLimit {
							logger.WithField("retry-count", work.retryCount).Debug("requeueing task start request")
							work.retryCount++
							time.Sleep(retryDelay)
							w.taskWork <- work
						}
					}
				}
				if work.RequestType == TaskStoppedType {
					if err := w.stopTask(work.Task.ID); err != nil {
						if work.retryCount < retryLimit {
							logger.WithField("retry-count", work.retryCount).Debug("requeueing task stop request")
							work.retryCount++
							time.Sleep(retryDelay)
							w.taskWork <- work
						}
					}
				}
				if work.RequestType == TaskCreatedType {
					w.createTask(work.Task.ID, work.Task.StartOnCreate)
				}
				if work.RequestType == TaskRemovedType {
					if err := w.removeTask(work.Task.ID); err != nil {
						if work.retryCount < retryLimit {
							logger.WithField("retry-count", work.retryCount).Debug("requeueing request")
							work.retryCount++
							time.Sleep(retryDelay)
							w.taskWork <- work
						}
					}
				}
			case <-w.quitChan:
				logger.Infof("stopping tribe worker")
				return
			}
		}
	}()

	// plugin worker
	w.waitGroup.Add(1)
	go func() {
		defer w.waitGroup.Done()
		logger.Debug("starting plugin worker")
		for {
			select {
			case work := <-w.pluginWork:
				// Receive a work request.
				logger := w.logger.WithFields(log.Fields{
					"plugin-name":    work.Plugin.Name(),
					"plugin-version": work.Plugin.Version(),
					"plugin-type":    work.Plugin.TypeName(),
					"request-type":   work.RequestType.String(),
				})
				logger.Debug("received plugin work")
				if work.RequestType == PluginLoadedType {
					if err := w.loadPlugin(work.Plugin); err != nil {
						if work.retryCount < retryLimit {
							logger.WithField("retry-count", work.retryCount).Debug("requeueing request")
							work.retryCount++
							time.Sleep(retryDelay)
							w.pluginWork <- work
						}
					}
				}
				if work.RequestType == PluginUnloadedType {
					if err := w.unloadPlugin(work.Plugin); err != nil {
						if work.retryCount < retryLimit {
							logger.WithField("retry-count", work.retryCount).Debug("requeueing request")
							work.retryCount++
							time.Sleep(retryDelay)
							w.pluginWork <- work
						}
					}
				}
			case <-w.quitChan:
				w.logger.Debug("stop tribe plugin worker")
				return
			}
		}
	}()
}
790322
func (r *Runner) Start() {
	r.lock.Lock()
	defer r.lock.Unlock()
	if r.stop == nil {
		c := make(chan struct{})
		r.stop = &c
		for i := range r.loopFuncs {
			go r.loopFuncs[i](*r.stop)
		}
	}
}
679457
func (c *Cron) Start() {
	if c.running {
		return
	}
	c.running = true
	go c.run()
}
866629
func (i *InvoiceRegistry) Start() error {
	i.wg.Add(1)

	go i.invoiceEventNotifier()

	return nil
}
504162
func (b *Breaker) Run(work func() error) error {
	state := atomic.LoadUint32(&b.state)

	if state == open {
		return ErrBreakerOpen
	}

	return b.doWork(state, work)
}
185043
func (gs *Server) StartRoutine() {
	gs.wg.Add(1)
	atomic.AddInt32(&gs.routinesCount, 1)
}
644735
func (worker *DbWorker) start() {
	worker.workInfo.Status(Start, worker)
	worker.ControlChannel <- func() (WorkerPhase, *DbWorker) { return Start, worker }
	for job := range worker.InputChannel {
		worker.invoke(job)
	}
	worker.workInfo.Status(Stop, worker)
	worker.ControlChannel <- func() (WorkerPhase, *DbWorker) { return Stop, worker }
	if worker.TimeoutChannel != nil {
		close(worker.TimeoutChannel)
	}
}
927351
func startWorker(container *DbWorkerContainer, db *DbGorp, id int) {
	newDb, _ := db.CloneDb(true)
	worker := &DbWorker{
		Db:         newDb,
		Id:         id,
		SharedData: map[string]interface{}{},
		SharedWorker: SharedWorker{
			workInfo:       container.workInfo,
			InputChannel:   container.InputChannel,
			OutputChannel:  container.OutputChannel,
			ControlChannel: container.ControlChannel,
		},
	}
	// Close the database after worker has ended (Start returned
	defer worker.Db.Close()
	container.mutex.Lock()
	container.Workers = append(container.Workers, worker)
	container.mutex.Unlock()
	// Only monitor jobs if Status function defined and a timeout is also defined
	if container.LongWorkTimeout > 0 {
		worker.TimeoutChannel = make(chan *timeoutInfo)
		go worker.TimeInfo.start(worker.TimeoutChannel, container.LongWorkTimeout)
	}
	worker.start()
}
59667
func (p *BulkProcessor) Start(ctx context.Context) error {
	p.startedMu.Lock()
	defer p.startedMu.Unlock()

	if p.started {
		return nil
	}

	// We must have at least one worker.
	if p.numWorkers < 1 {
		p.numWorkers = 1
	}

	p.requestsC = make(chan BulkableRequest)
	p.executionId = 0
	p.stats = newBulkProcessorStats(p.numWorkers)
	p.stopReconnC = make(chan struct{})

	// Create and start up workers.
	p.workers = make([]*bulkWorker, p.numWorkers)
	for i := 0; i < p.numWorkers; i++ {
		p.workerWg.Add(1)
		p.workers[i] = newBulkWorker(p, i)
		go p.workers[i].work(ctx)
	}

	// Start the ticker for flush (if enabled)
	if int64(p.flushInterval) > 0 {
		p.flusherStopC = make(chan struct{})
		go p.flusher(p.flushInterval)
	}

	p.started = true

	return nil
}
383357
func (w *watcher) start() {
	if w.starting || w.running {
		return
	}
	w.starting = true
	go w.loop()
}
1038393
func (c *Client) StartWorkflow(request StartWorkflowRequest) (*StartWorkflowResponse, error) {
	resp := &StartWorkflowResponse{}
	err := c.swfReqWithResponse("StartWorkflowExecution", request, resp)
	return resp, err
}
333419
func (driver *MesosExecutorDriver) Start() (mesosproto.Status, error) {
	driver.lock.Lock()
	defer driver.lock.Unlock()
	return driver.start()
}
608120
func (w *workManager) Start() {

	w.mutex.Lock()
	defer w.mutex.Unlock()

	if w.state == workManagerStopped {
		w.state = workManagerRunning
		go func() {
			for {
				select {
				case <-w.collectq.Err:
					//TODO: log error
				case <-w.processq.Err:
					//TODO: log error
				case <-w.publishq.Err:
					//TODO: log error
				case <-w.kill:
					return
				}
			}
		}()
	}
}
279502
func (config ManifoldConfig) start(context dependency.Context) (worker.Worker, error) {
	if err := config.Validate(); err != nil {
		return nil, errors.Trace(err)
	}

	var clock clock.Clock
	if err := context.Get(config.ClockName, &clock); err != nil {
		return nil, errors.Trace(err)
	}

	if config.RaftName != "" {
		// We don't need anything from raft directly, but if it's set
		// ensure it's running before continuing.
		if err := context.Get(config.RaftName, nil); err != nil {
			return nil, errors.Trace(err)
		}
	}

	cleanup := func() error { return nil }
	var updaterFunc func() (globalclock.Updater, error)
	if config.StateName != "" {
		var stTracker workerstate.StateTracker
		if err := context.Get(config.StateName, &stTracker); err != nil {
			return nil, errors.Trace(err)
		}
		statePool, err := stTracker.Use()
		if err != nil {
			return nil, errors.Trace(err)
		}
		cleanup = stTracker.Done
		updaterFunc = statePool.SystemState().GlobalClockUpdater
	} else {

		var updater globalclock.Updater
		if err := context.Get(config.LeaseManagerName, &updater); err != nil {
			return nil, errors.Trace(err)
		}
		updaterFunc = func() (globalclock.Updater, error) {
			return updater, nil
		}
	}

	worker, err := config.NewWorker(Config{
		NewUpdater:     updaterFunc,
		LocalClock:     clock,
		UpdateInterval: config.UpdateInterval,
		BackoffDelay:   config.BackoffDelay,
		Logger:         config.Logger,
	})
	if err != nil {
		cleanup()
		return nil, errors.Trace(err)
	}

	go func() {
		worker.Wait()
		cleanup()
	}()
	return worker, nil
}