// Run re-provides keys with 'tick' interval or when triggered
433627
func (rp *Reprovider) Run(tick time.Duration) {
	// dont reprovide immediately.
	// may have just started the daemon and shutting it down immediately.
	// probability( up another minute | uptime ) increases with uptime.
	after := time.After(time.Minute)
	var done doneFunc
	for {
		if tick == 0 {
			after = make(chan time.Time)
		}

		select {
		case <-rp.ctx.Done():
			return
		case done = <-rp.trigger:
		case <-after:
		}

		//'mute' the trigger channel so when `ipfs bitswap reprovide` is called
		//a 'reprovider is already running' error is returned
		unmute := rp.muteTrigger()

		err := rp.Reprovide()
		if err != nil {
			log.Debug(err)
		}

		if done != nil {
			done(err)
		}

		unmute()

		after = time.After(tick)
	}
}
790024
func (a *Ace) Run(addr string) {
	if err := http.ListenAndServe(addr, a); err != nil {
		panic(err)
	}
}
564707
func (c *configCommand) Run(ctx *cmd.Context) error {
	client, err := c.getAPI()
	if err != nil {
		return errors.Trace(err)
	}
	defer func() { _ = client.Close() }()

	if len(c.resetKeys) > 0 {
		if err := c.resetConfig(client, ctx); err != nil {
			// We return this error naked as it is almost certainly going to be
			// cmd.ErrSilent and the cmd.Command framework expects that back
			// from cmd.Run if the process is blocked.
			return err
		}
	}
	if c.action == nil {
		// If we are reset only, we end up here; we have already done that.
		return nil
	}

	return c.action(client, ctx)
}
189473
func (e *PaperKeyPrimary) Run(m libkb.MetaContext) error {
	var err error
	e.passphrase, err = libkb.MakePaperKeyPhrase(libkb.PaperKeyVersion)
	if err != nil {
		return err
	}

	kgarg := &PaperKeyGenArg{
		Passphrase:     e.passphrase,
		Me:             e.args.Me,
		SigningKey:     e.args.SigningKey,
		EncryptionKey:  e.args.EncryptionKey,
		PerUserKeyring: e.args.PerUserKeyring,
	}
	kgeng := NewPaperKeyGen(e.G(), kgarg)
	if err := RunEngine2(m, kgeng); err != nil {
		return err
	}

	// If they refuse to write down their key, don't kill the login flow, just print an
	// ugly warning, which likely they won't see...
	w := m.UIs().LoginUI.DisplayPrimaryPaperKey(m.Ctx(), keybase1.DisplayPrimaryPaperKeyArg{Phrase: e.passphrase.String()})
	if w != nil {
		m.G().Log.Errorf("Display paper key failure: %s", w.Error())
	}

	return nil
}
138240
func (mod *CronBee) Run(eventChan chan bees.Event) {
	mod.eventChan = eventChan
	timer := cron.ParseInput(mod.input)
	for {
		select {
		case <-mod.SigChan:
			return

		case <-time.After(timer.DurationUntilNextEvent()):
			event := bees.Event{
				Bee:  mod.Name(),
				Name: "time",
				Options: []bees.Placeholder{
					{
						Name:  "timestamp",
						Type:  "string",
						Value: timer.GetNextEvent(),
					},
				},
			}
			mod.eventChan <- event
		}
	}
}
1139541
func (b *Bucketer) Run(publishInterval time.Duration) {
	done := false

	publishTickChan := time.NewTicker(publishInterval)

	for !done {
		select {
		case stat := <-b.input:
			log.Debugf("Bucketer got %+v", *stat)
			b.insert(stat)
		case done = <-b.shutdown:
			log.Debug("Bucketer shutting down ", time.Now())
			// TODO: drain remaining stats
			publishTickChan.Stop()
			b.pub()
			break
		case <-publishTickChan.C:
			log.Debug("Bucketer publish interval elapsed ", time.Now())
			b.pub()
		case <-time.After(time.Second * 1):
			log.Debug("Bucketer Run() timeout ", time.Now())
		}

		if time.Now().UTC().After(b.futureBucketMinTime) {
			log.Debug("Bucketer advancing ", time.Now())
			b.next()
		}
	}

	log.Info("Bucketer Run() exiting ", time.Now())
}
1301742
func (e *PGPPurge) Run(m libkb.MetaContext) error {
	me, err := libkb.LoadMe(libkb.NewLoadUserPubOptionalArg(e.G()))
	if err != nil {
		return err
	}
	e.me = me

	// get all PGP blocks in keyring
	ring, err := m.ActiveDevice().Keyring(m)
	if err != nil {
		return err
	}
	blocks, err := ring.AllPGPBlocks()
	if err != nil {
		return err
	}

	// export each one to a file
	if err := e.exportBlocks(m, blocks); err != nil {
		return err
	}

	if e.arg.DoPurge {
		// if purge flag set, remove all PGP blocks from keyring and save it
		err = ring.RemoveAllPGPBlocks()
		if err != nil {
			return err
		}
		err = ring.Save()
		if err != nil {
			return err
		}
	}

	return nil
}
714807
func (rp *Reprovider) Run(proc goprocess.Process) {
	ctx := goprocessctx.WithProcessClosing(rp.ctx, proc)
	defer close(rp.closing)

	// dont reprovide immediately.
	// may have just started the daemon and shutting it down immediately.
	// probability( up another minute | uptime ) increases with uptime.
	after := time.After(time.Minute)
	var done doneFunc
	for {
		if rp.tick == 0 {
			after = make(chan time.Time)
		}

		select {
		case <-ctx.Done():
			return
		case done = <-rp.trigger:
		case <-after:
		}

		// 'mute' the trigger channel so when `ipfs bitswap reprovide` is called
		// a 'reprovider is already running' error is returned
		unmute := rp.muteTrigger()

		err := rp.reprovide(ctx)
		if err != nil {
			log.Debug(err)
		}

		if done != nil {
			done(err)
		}

		unmute()

		after = time.After(rp.tick)
	}
}
926414
func (eng *Engine) Run() error {
	defer eng.free()
	eng.transport.Bind(eng.connection)
	eng.tick() // Start ticking if needed
	for eng.dispatch() {
		// Initiate read/write if needed
		eng.read()
		eng.write()
		select {
		case f := <-eng.inject: // User or IO action
			f()
		case <-eng.timer.C:
			eng.tick()
		}
	}
	eng.err.Set(EndpointError(eng.Connection()))
	eng.err.Set(eng.Transport().Condition().Error())
	close(eng.running)   // Signal goroutines have exited and Error is set, disable Inject()
	_ = eng.conn.Close() // Close conn, force read goroutine to exit (Inject will fail)
	return eng.err.Get()
}
1034209
func (c *removeKeysCommand) Run(context *cmd.Context) error {
	client, err := c.NewKeyManagerClient()
	if err != nil {
		return err
	}
	defer client.Close()

	// TODO(alexisb) - currently keys are global which is not ideal.
	// keymanager needs to be updated to allow keys per user
	c.user = "admin"
	results, err := client.DeleteKeys(c.user, c.keyIds...)
	if err != nil {
		return block.ProcessBlockedError(err, block.BlockChange)
	}
	for i, result := range results {
		if result.Error != nil {
			fmt.Fprintf(context.Stderr, "cannot remove key id %q: %v\n", c.keyIds[i], result.Error)
		}
	}
	return nil
}
663118
func (c *CharmResourcesCommand) Run(ctx *cmd.Context) error {
	return c.baseRun(ctx)
}
518960
func (j *Job) run() (result []reflect.Value, err error) {
	f := reflect.ValueOf(j.funcs[j.jobFunc])
	params := j.fparams[j.jobFunc]
	if len(params) != f.Type().NumIn() {
		err = errors.New("the number of param is not adapted")
		return
	}
	in := make([]reflect.Value, len(params))
	for k, param := range params {
		in[k] = reflect.ValueOf(param)
	}
	result = f.Call(in)
	j.lastRun = time.Now()
	j.scheduleNextRun()
	return
}
59575
func (s *Script) Run(c scripter, keys []string, args ...interface{}) *Cmd {
	r := s.EvalSha(c, keys, args...)
	if err := r.Err(); err != nil && strings.HasPrefix(err.Error(), "NOSCRIPT ") {
		return s.Eval(c, keys, args...)
	}
	return r
}
272511
func (e *PaperKey) Run(m libkb.MetaContext) error {
	m.G().LocalSigchainGuard().Set(m.Ctx(), "PaperKey")
	defer m.G().LocalSigchainGuard().Clear(m.Ctx(), "PaperKey")

	me, err := libkb.LoadMe(libkb.NewLoadUserArgWithMetaContext(m))
	if err != nil {
		return err
	}

	// check for existing paper keys
	cki := me.GetComputedKeyInfos()
	if cki == nil {
		return fmt.Errorf("no computed key infos")
	}

	var needReload bool
	var devicesToRevoke []*libkb.Device
	for i, bdev := range cki.PaperDevices() {
		revoke, err := m.UIs().LoginUI.PromptRevokePaperKeys(context.TODO(),
			keybase1.PromptRevokePaperKeysArg{
				Device: *bdev.ProtExport(),
				Index:  i,
			})
		if err != nil {
			m.Warning("prompt error: %s", err)
			return err
		}
		if revoke {
			devicesToRevoke = append(devicesToRevoke, bdev)
		}
	}

	// Revoke all keys at once, not one-by-one. This way, a cancelation of the
	// experience above will stop all operations
	for _, bdev := range devicesToRevoke {
		reng := NewRevokeDeviceEngine(m.G(), RevokeDeviceEngineArgs{ID: bdev.ID})
		if err := RunEngine2(m, reng); err != nil {
			// probably not a good idea to continue...
			return err
		}
		needReload = true
	}

	if needReload {
		me, err = libkb.LoadMe(libkb.NewLoadUserArgWithMetaContext(m))
		if err != nil {
			return err
		}
	}

	ska1 := libkb.SecretKeyArg{
		Me:      me,
		KeyType: libkb.DeviceSigningKeyType,
	}
	signingKey, err := m.G().Keyrings.GetSecretKeyWithPrompt(m, m.SecretKeyPromptArg(ska1, "You must sign your new paper key"))
	if err != nil {
		return err
	}

	ska2 := libkb.SecretKeyArg{
		Me:      me,
		KeyType: libkb.DeviceEncryptionKeyType,
	}
	encryptionKeyGeneric, err := m.G().Keyrings.GetSecretKeyWithPrompt(m, m.SecretKeyPromptArg(ska2, "You must encrypt for your new paper key"))
	if err != nil {
		return err
	}
	encryptionKey, ok := encryptionKeyGeneric.(libkb.NaclDHKeyPair)
	if !ok {
		return fmt.Errorf("Unexpected encryption key type")
	}

	e.passphrase, err = libkb.MakePaperKeyPhrase(libkb.PaperKeyVersion)
	if err != nil {
		return err
	}

	kgarg := &PaperKeyGenArg{
		Passphrase:     e.passphrase,
		Me:             me,
		SigningKey:     signingKey,
		EncryptionKey:  encryptionKey,
		PerUserKeyring: nil,
	}
	e.gen = NewPaperKeyGen(m.G(), kgarg)
	if err := RunEngine2(m, e.gen); err != nil {
		return err
	}

	return m.UIs().LoginUI.DisplayPaperKeyPhrase(m.Ctx(), keybase1.DisplayPaperKeyPhraseArg{Phrase: e.passphrase.String()})

}
291069
func (h HookFunc) Run(e *Event, level Level, message string) {
	h(e, level, message)
}
926074
func (r *RegisterMonitor) Run() {
	// Grab the lock and set our state. If we're not idle, then we return
	// immediately since the monitor is only allowed to run once.
	r.lock.Lock()
	if r.runState != registerStateIdle {
		r.lock.Unlock()
		return
	}
	r.runState = registerStateRunning
	r.lock.Unlock()

	// Start a goroutine that just waits for a stop request
	stopCh := make(chan struct{})
	go func() {
		defer close(stopCh)
		r.lock.Lock()
		defer r.lock.Unlock()

		// We wait for anything not running, just so we're more resilient
		// in the face of state machine issues. Basically any state change
		// will cause us to quit.
		for r.runState == registerStateRunning {
			r.cond.Wait()
		}
	}()

	// When we exit, we set the state to stopped and broadcast to any
	// waiting Close functions that they can return.
	defer func() {
		r.lock.Lock()
		r.runState = registerStateStopped
		r.cond.Broadcast()
		r.lock.Unlock()
	}()

	// Run the first registration optimistically. If this fails then its
	// okay since we'll just retry shortly.
	r.register()

	// Create the timers for trigger events. We don't use tickers because
	// we don't want the events to pile on.
	reconcileTimer := time.NewTimer(r.ReconcilePeriod)
	heartbeatTimer := time.NewTimer(r.TTLPeriod / 3)

	for {
		select {
		case <-reconcileTimer.C:
			r.register()
			reconcileTimer.Reset(r.ReconcilePeriod)

		case <-heartbeatTimer.C:
			r.heartbeat()
			heartbeatTimer.Reset(r.TTLPeriod / 3)

		case <-stopCh:
			r.Logger.Printf("[INFO] proxy: stop request received, deregistering")
			r.deregister()
			return
		}
	}
}
636344
func (c *showOutputCommand) Run(ctx *cmd.Context) error {
	// Check whether units were left off our time string.
	r := regexp.MustCompile("[a-zA-Z]")
	matches := r.FindStringSubmatch(c.wait[len(c.wait)-1:])
	// If any match, we have units.  Otherwise, we don't; assume seconds.
	if len(matches) == 0 {
		c.wait = c.wait + "s"
	}

	waitDur, err := time.ParseDuration(c.wait)
	if err != nil {
		return err
	}

	api, err := c.NewActionAPIClient()
	if err != nil {
		return err
	}
	defer api.Close()

	wait := time.NewTimer(0 * time.Second)

	switch {
	case waitDur.Nanoseconds() < 0:
		// Negative duration signals immediate return.  All is well.
	case waitDur.Nanoseconds() == 0:
		// Zero duration signals indefinite wait.  Discard the tick.
		wait = time.NewTimer(0 * time.Second)
		_ = <-wait.C
	default:
		// Otherwise, start an ordinary timer.
		wait = time.NewTimer(waitDur)
	}

	result, err := GetActionResult(api, c.requestedId, wait)
	if err != nil {
		return errors.Trace(err)
	}

	return c.out.Write(ctx, FormatActionResult(result))
}