// Run the event controller
496263
func (ec *ServiceManager) Run() (err error) {

	// Launch services
	for _, s := range ec.services {
		ec.wg.Add(1)
		go ec.execute(s)
	}

	// Start event loop
	go ec.eventLoop()

	return nil
}
27465
func (mod *PrometheusBee) Run(eventChan chan bees.Event) {

	// Counter vector registration

	mod.counter = prometheus.NewCounterVec(
		prometheus.CounterOpts{
			Name: mod.counterVecName,
			Help: "Collection of all counter variables being iterated by hives",
		},
		[]string{"name"},
	)
	err := prometheus.Register(mod.counter)
	if err != nil {
		mod.LogErrorf("Error registering counter vector: %v", err)
		panic("Unable to start Prometheus due to counter initialization failure")
	}

	// Gauge vector registration

	mod.gauge = prometheus.NewGaugeVec(
		prometheus.GaugeOpts{
			Name: mod.gaugeVecName,
			Help: "Collection of all gauge variables being iterated by hives",
		},
		[]string{"name"},
	)
	err = prometheus.Register(mod.gauge)
	if err != nil {
		mod.LogErrorf("Error registering gauge vector: %v", err)
		panic("Unable to start Prometheus due to gauge initialization failure")
	}

	// Histogram vector registration

	mod.histogram = prometheus.NewHistogramVec(
		prometheus.HistogramOpts{
			Name: mod.histogramVecName,
			Help: "Collection of all histogram variables being iterated by hives",
		},
		[]string{"name"},
	)
	err = prometheus.Register(mod.histogram)
	if err != nil {
		mod.LogErrorf("Error registering histogram vector: %v", err)
		panic("Unable to start Prometheus due to histogram initialization failure")
	}

	// Summary vector registration

	mod.summary = prometheus.NewSummaryVec(
		prometheus.SummaryOpts{
			Name: mod.summaryVecName,
			Help: "Collection of all summary variables being iterated by hives",
		},
		[]string{"name"},
	)
	err = prometheus.Register(mod.summary)
	if err != nil {
		mod.LogErrorf("Error registering summary vector: %v", err)
		panic("Unable to start Prometheus due to summary initialization failure")
	}

	// Now, to serve everything up:

	go func() {
		http.Handle("/metrics", promhttp.Handler())
		err := http.ListenAndServe(":2112", nil)
		if err != nil {
			mod.LogErrorf("Error running prometheus metric handler: %v", err)
		}
	}()

	select {
	case <-mod.SigChan:
		return
	}
}
285948
func (c *listCommand) Run(ctx *cmd.Context) (err error) {
	if c.all {
		return c.listForController(ctx)
	}
	return c.listForModel(ctx)
}
306903
func (mod *CleverbotBee) Run(eventChan chan bees.Event) {
	mod.evchan = eventChan

	client, err := cleverbot.New(mod.api_user, mod.api_key, mod.session_nick)
	if err != nil {
		mod.LogErrorf("Failed to start session: %v", err)
		return
	}
	mod.client = client

	select {
	case <-mod.SigChan:
		return
	}
}
972710
func (mod *FacebookBee) Run(eventChan chan bees.Event) {
	mod.evchan = eventChan

	since := strconv.FormatInt(time.Now().UTC().Unix(), 10)
	timeout := time.Duration(10 * time.Second)

	for {
		select {
		case <-mod.SigChan:
			return
		case <-time.After(time.Duration(timeout)):
			var err error
			since, err = mod.handleStream(since)
			if err != nil {
				panic(err)
			}
		}

		timeout = time.Minute
	}
}
224943
func (c *killCommand) Run(ctx *cmd.Context) error {
	controllerName, err := c.ControllerName()
	if err != nil {
		return errors.Trace(err)
	}
	store := c.ClientStore()
	if !c.assumeYes {
		if err := confirmDestruction(ctx, controllerName); err != nil {
			return err
		}
	}

	// Attempt to connect to the API.
	api, err := c.getControllerAPIWithTimeout(10 * time.Second)
	switch errors.Cause(err) {
	case nil:
		defer api.Close()
	case common.ErrPerm:
		return errors.Annotate(err, "cannot destroy controller")
	default:
		ctx.Infof("Unable to open API: %s\n", err)
	}

	// Obtain controller environ so we can clean up afterwards.
	controllerEnviron, err := c.getControllerEnviron(ctx, store, controllerName, api)
	if err != nil {
		return errors.Annotate(err, "getting controller environ")
	}
	cloudCallCtx := cloudCallContext(c.controllerCredentialAPIFunc)
	// If we were unable to connect to the API, just destroy the controller through
	// the environs interface.
	if api == nil {
		ctx.Infof("Unable to connect to the API server, destroying through provider")
		return c.environsDestroy(controllerName, controllerEnviron, cloudCallCtx, store)
	}

	// Attempt to destroy the controller and all models and storage.
	destroyStorage := true
	err = api.DestroyController(controller.DestroyControllerParams{
		DestroyModels:  true,
		DestroyStorage: &destroyStorage,
	})
	if err != nil {
		ctx.Infof("Unable to destroy controller through the API: %s\nDestroying through provider", err)
		return c.environsDestroy(controllerName, controllerEnviron, cloudCallCtx, store)
	}

	ctx.Infof("Destroying controller %q\nWaiting for resources to be reclaimed", controllerName)

	uuid := controllerEnviron.Config().UUID()
	if err := c.WaitForModels(ctx, api, uuid); err != nil {
		c.DirectDestroyRemaining(ctx, api)
	}
	return c.environsDestroy(controllerName, controllerEnviron, cloudCallCtx, store)
}
1373941
func (mod *PastebinBee) Run(eventChan chan bees.Event) {
	mod.client = pastebin.NewPastebin(mod.apiDevKey)
}
1050930
func (o *Organizer) Run() {
	if o.only != nil {
		o.runTest(o.only)
		return
	}

	for _, test := range o.tests {
		o.runTest(&test)
	}
}
432138
func (nc *Controller) Run(stopCh <-chan struct{}) {
	defer utilruntime.HandleCrash()

	klog.Infof("Starting ipam controller")
	defer klog.Infof("Shutting down ipam controller")

	if !controller.WaitForCacheSync("node", stopCh, nc.nodeInformerSynced) {
		return
	}

	if nc.allocatorType != ipam.IPAMFromClusterAllocatorType && nc.allocatorType != ipam.IPAMFromCloudAllocatorType {
		go nc.cidrAllocator.Run(stopCh)
	}

	<-stopCh
}
566186
func (mod *DevrantBee) Run(eventChan chan bees.Event) {
	mod.evchan = eventChan

	// Setting up the client, unfortunately we can't really log in as an user
	mod.client = devgorant.New()
}
1328169
func (c *TriggerController) Run(workers int, stopCh <-chan struct{}) {
	defer utilruntime.HandleCrash()
	defer c.queue.ShutDown()

	klog.Infof("Starting trigger controller")

	if !cache.WaitForCacheSync(stopCh, c.syncs...) {
		utilruntime.HandleError(fmt.Errorf("timed out waiting for caches to sync"))
		return
	}

	for i := 0; i < workers; i++ {
		go wait.Until(c.imageStreamWorker, time.Second, stopCh)
	}

	for i := 0; i < workers; i++ {
		go wait.Until(c.resourceWorker, time.Second, stopCh)
	}

	<-stopCh
	klog.Infof("Shutting down trigger controller")
}
942981
func (c *ImageStreamController) Run(workers int, stopCh <-chan struct{}) {
	defer utilruntime.HandleCrash()
	defer c.queue.ShutDown()

	klog.Infof("Starting image stream controller")

	// Wait for the stream store to sync before starting any work in this controller.
	if !cache.WaitForCacheSync(stopCh, c.listerSynced) {
		utilruntime.HandleError(fmt.Errorf("timed out waiting for caches to sync"))
		return
	}

	for i := 0; i < workers; i++ {
		go wait.Until(c.worker, time.Second, stopCh)
	}

	metrics.InitializeImportCollector(false, c.importCounter.Collect)

	<-stopCh
	klog.Infof("Shutting down image stream controller")
}
964777
func (c *TemplateInstanceController) Run(workers int, stopCh <-chan struct{}) {
	defer utilruntime.HandleCrash()
	defer c.queue.ShutDown()

	if !cache.WaitForCacheSync(stopCh, c.informer.HasSynced) {
		return
	}

	klog.V(2).Infof("Starting TemplateInstance controller")

	for i := 0; i < workers; i++ {
		go wait.Until(c.runWorker, time.Second, stopCh)
	}

	<-stopCh
}
704311
func (c *PodController) Run() {
	glog.Infof("starting pod controller")

	stopCh := c.StopChannel()
	go c.runWatcher(stopCh)

	<-stopCh
	glog.Infof("shutting down pod controller")
}
706543
func (rsc *ReplicaSetController) Run(workers int, stopCh <-chan struct{}) {
	defer utilruntime.HandleCrash()
	defer rsc.queue.ShutDown()

	controllerName := strings.ToLower(rsc.Kind)
	klog.Infof("Starting %v controller", controllerName)
	defer klog.Infof("Shutting down %v controller", controllerName)

	if !controller.WaitForCacheSync(rsc.Kind, stopCh, rsc.podListerSynced, rsc.rsListerSynced) {
		return
	}

	for i := 0; i < workers; i++ {
		go wait.Until(rsc.worker, time.Second, stopCh)
	}

	<-stopCh
}
390161
func (c *DNSController) Run() {
	glog.Infof("starting DNS controller")

	stopCh := c.StopChannel()
	go c.runWatcher(stopCh)

	<-stopCh
	glog.Infof("shutting down DNS controller")
}
968057
func (mod *SlackBee) Run(eventChan chan bees.Event) {
	rtm := mod.client.NewRTM()
	defer rtm.Disconnect()

	go rtm.ManageConnection()

	// Cache the channels
	for k := range mod.channels {
		mod.findChannelID(k, true)
	}

	for {
		select {
		case <-mod.SigChan:
			return

		case msg := <-rtm.IncomingEvents:
			switch ev := msg.Data.(type) {
			case *slack.MessageEvent:
				if stringInMap(ev.Channel, mod.channels) {
					u := ev.Msg.User
					if u == "" {
						u = ev.Msg.Username
					}
					t := ev.Msg.Text
					if t == "" {
						for _, v := range ev.Msg.Attachments {
							sendEvent(mod.Name(), ev.Channel, u, v.Text, eventChan)
						}
					} else {
						sendEvent(mod.Name(), ev.Channel, u, t, eventChan)
					}
				}
			case *slack.RTMError:
				mod.LogErrorf("Error: %s", ev.Error())
			case *slack.InvalidAuthEvent:
				mod.LogErrorf("Error: invalid credentials")
				return
			default:
				// Ignore other events..
				// fmt.Printf("Unexpected: %v\n", msg.Data)
			}
		}
	}
}