// NewWorker returns a new global clock updater worker, using the given
// configuration.
482062
func NewWorker(config Config) (worker.Worker, error) {
	if err := config.Validate(); err != nil {
		return nil, errors.Annotate(err, "validating config")
	}
	updater, err := config.NewUpdater()
	if err != nil {
		return nil, errors.Annotate(err, "getting new updater")
	}
	w := &updaterWorker{
		config:  config,
		updater: updater,
	}
	w.tomb.Go(w.loop)
	return w, nil
}
173460
func NewEventWorker(cl *trace.Client, stats *statsd.Client) *EventWorker {
	return &EventWorker{
		sampleChan:  make(chan ssf.SSFSample),
		mutex:       &sync.Mutex{},
		traceClient: cl,
		stats:       stats,
	}
}
1286300
func (config ManifoldConfig) newWorker(a agent.Agent, apiCaller base.APICaller) (worker.Worker, error) {
	if err := config.Validate(); err != nil {
		return nil, errors.Trace(err)
	}

	// Ensure that we have a machine tag.
	agentCfg := a.CurrentConfig()
	tag, ok := agentCfg.Tag().(names.MachineTag)
	if !ok {
		return nil, errors.Errorf("expected a machine tag, got %v", tag)
	}

	// Partially apply the NewFacade method and pass it as a factory.
	// This is so the worker can use the API server in different contexts.
	// TODO (manadart 2018-08-30): This behaviour is vestigial.
	// We no longer need a factory and can pass a concrete facade.
	newFacade := func(t names.Tag) Facade {
		return config.NewFacade(apiCaller, t)
	}

	// Partially apply Upgrader factory function so we only need to request
	// using the getter for the target OS series.
	newUpgrader := func(targetSeries string) (Upgrader, error) {
		return NewUpgrader(targetSeries, service.NewServiceManagerWithDefaults(), config.Logger)
	}

	cfg := Config{
		Tag:             tag,
		Logger:          config.Logger,
		FacadeFactory:   newFacade,
		Service:         &serviceAccess{},
		UpgraderFactory: newUpgrader,
	}

	w, err := config.NewWorker(cfg)
	return w, errors.Annotate(err, "starting machine upgrade series worker")
}
1086537
func New(config Config) (*Worker, error) {
	if err := config.Validate(); err != nil {
		return nil, errors.Trace(err)
	}

	// Soon we will get model specific logs generated in the
	// controller logged against the model. Until then, distinguish
	// the logs from different migrationmaster insteads using the
	// model UUID suffix.
	loggerName := "juju.worker.migrationmaster." + config.ModelUUID[len(config.ModelUUID)-6:]
	logger := loggo.GetLogger(loggerName)

	w := &Worker{
		config: config,
		logger: logger,
	}
	err := catacomb.Invoke(catacomb.Plan{
		Site: &w.catacomb,
		Work: w.run,
	})
	if err != nil {
		return nil, errors.Trace(err)
	}
	return w, nil
}
653547
func NewWorker(config Config) (worker.Worker, error) {
	if err := config.Validate(); err != nil {
		return nil, errors.Trace(err)
	}
	paths := NewPaths(config.DataDir, names.NewApplicationTag(config.Application))
	deployer, err := jujucharm.NewDeployer(
		paths.State.CharmDir,
		paths.State.DeployerDir,
		jujucharm.NewBundlesDir(paths.State.BundlesDir, config.Downloader),
	)
	if err != nil {
		return nil, errors.Annotatef(err, "cannot create deployer")
	}

	op := &caasOperator{
		config:   config,
		paths:    paths,
		deployer: deployer,
		runner: worker.NewRunner(worker.RunnerParams{
			Clock: config.Clock,

			// One of the uniter workers failing should not
			// prevent the others from running.
			IsFatal: func(error) bool { return false },

			// For any failures, try again in 3 seconds.
			RestartDelay: 3 * time.Second,
		}),
	}
	if err := catacomb.Invoke(catacomb.Plan{
		Site: &op.catacomb,
		Work: op.loop,
		Init: []worker.Worker{op.runner},
	}); err != nil {
		return nil, errors.Trace(err)
	}
	return op, nil
}
800572
func NewCertificateUpdater(config Config) worker.Worker {
	return legacy.NewNotifyWorker(&CertificateUpdater{
		addressWatcher:  config.AddressWatcher,
		configGetter:    config.ControllerConfigGetter,
		hostPortsGetter: config.APIHostPortsGetter,
		getter:          config.StateServingInfoGetter,
		setter:          config.StateServingInfoSetter,
	})
}
933222
func (server *Server) NewWorker(consumerTag string, concurrency int) *Worker {
	return &Worker{
		server:      server,
		ConsumerTag: consumerTag,
		Concurrency: concurrency,
		Queue:       "",
	}
}
1323814
func NewPingWorker(wr *wrangler.Wrangler, message string) (Worker, error) {
	return &PingWorker{
		StatusWorker: NewStatusWorker(),
		wr:           wr,
		message:      message,
	}, nil
}
986112
func NewContainerWorker(config Config) (worker.Worker, error) {
	m, err := config.Facade.Machine(config.Tag.(names.MachineTag))
	if err != nil {
		return nil, errors.Trace(err)
	}
	config.GetRequiredLXDProfiles = func(_ string) []string { return []string{"default"} }
	config.GetMachineWatcher = m.WatchContainers
	return newWorker(config)
}
493923
func NewWorker(config Config) (worker.Worker, error) {
	if err := config.Validate(); err != nil {
		return nil, errors.Trace(err)
	}

	w := &Worker{
		logger: config.Logger,
		update: config.UpdateControllerAPIPort,
	}

	servingInfo, ok := config.AgentConfig.StateServingInfo()
	if !ok {
		return nil, errors.New("missing state serving info")
	}
	w.controllerAPIPort = servingInfo.ControllerAPIPort
	// We need to make sure that update the agent config with
	// the potentially new controller api port from the database
	// before we start any other workers that need to connect
	// to the controller over the controller port.
	w.updateControllerPort(config.ControllerAPIPort)

	unsub, err := config.Hub.Subscribe(controller.ConfigChanged,
		func(topic string, data controller.ConfigChangedMessage, err error) {
			if w.updateControllerPort(data.Config.ControllerAPIPort()) {
				w.tomb.Kill(dependency.ErrBounce)
			}
		})
	if err != nil {
		return nil, errors.Annotate(err, "unable to subscribe to details topic")
	}

	w.tomb.Go(func() error {
		defer unsub()
		<-w.tomb.Dying()
		return nil
	})
	return w, nil
}
71490
func NewWorker(config Config) (RestoreStatusWorker, error) {
	if err := config.Validate(); err != nil {
		return nil, errors.Trace(err)
	}
	restoreStatus, err := config.RestoreInfoWatcher.RestoreStatus()
	if err != nil {
		return nil, errors.Trace(err)
	}
	w := &restoreWorker{
		config: config,
		status: restoreStatus,
	}
	if err := catacomb.Invoke(catacomb.Plan{
		Site: &w.catacomb,
		Work: w.loop,
	}); err != nil {
		return nil, errors.Trace(err)
	}
	return w, nil
}
79515
func s_worker_new(identity string) worker_t {
	return worker_t{
		identity:  identity,
		id_string: identity,
		expire:    time.Now().Add(HEARTBEAT_INTERVAL * HEARTBEAT_LIVENESS),
	}
}
799855
func newUpgradeWorker(config Config, targetVersion int) (worker.Worker, error) {
	currentVersion, err := config.Facade.ModelEnvironVersion(config.ModelTag)
	if err != nil {
		return nil, errors.Trace(err)
	}

	return jujuworker.NewSimpleWorker(func(<-chan struct{}) error {
		// NOTE(axw) the abort channel is ignored, because upgrade
		// steps are not interruptible. If we find they need to be
		// interruptible, we should consider passing through a
		// context.Context for cancellation, and cancelling it if
		// the abort channel is signalled.
		setVersion := func(v int) error {
			return config.Facade.SetModelEnvironVersion(config.ModelTag, v)
		}
		setStatus := func(s status.Status, info string) error {
			return config.Facade.SetModelStatus(config.ModelTag, s, info, nil)
		}
		if targetVersion > currentVersion {
			if err := setStatus(status.Busy, fmt.Sprintf(
				"upgrading environ from version %d to %d",
				currentVersion, targetVersion,
			)); err != nil {
				return errors.Trace(err)
			}
		}
		if err := runEnvironUpgradeSteps(
			config.Environ,
			config.ControllerTag,
			config.ModelTag,
			currentVersion,
			targetVersion,
			setVersion,
			common.NewCloudCallContext(config.CredentialAPI, nil),
		); err != nil {
			info := fmt.Sprintf("failed to upgrade environ: %s", err)
			if err := setStatus(status.Error, info); err != nil {
				logger.Warningf("failed to update model status: %v", err)
			}
			return errors.Annotate(err, "upgrading environ")
		}
		if err := setStatus(status.Available, ""); err != nil {
			return errors.Trace(err)
		}
		config.GateUnlocker.Unlock()
		return nil
	}), nil
}
1331234
func NewMinUnitsWorker(st *state.State) worker.Worker {
	mu := &MinUnitsWorker{st: st}
	return legacy.NewStringsWorker(mu)
}
1062932
func NewWorker() (w *Worker) {
	astilog.Info("astiworker: starting worker...")
	w = &Worker{wg: &sync.WaitGroup{}}
	w.ctx, w.cancel = context.WithCancel(context.Background())
	w.wg.Add(1)
	return
}
456474
func NewDeployer(st *apideployer.State, ctx Context) (worker.Worker, error) {
	d := &Deployer{
		st:       st,
		ctx:      ctx,
		deployed: make(set.Strings),
	}
	w, err := watcher.NewStringsWorker(watcher.StringsConfig{
		Handler: d,
	})
	if err != nil {
		return nil, errors.Trace(err)
	}
	return w, nil
}
1250318
func NewLogger(api LoggerAPI, tag names.Tag, loggingOverride string, updateCallback func(string) error) (worker.Worker, error) {
	logger := &Logger{
		api:            api,
		tag:            tag,
		updateCallback: updateCallback,
		lastConfig:     loggo.LoggerInfo(),
		configOverride: loggingOverride,
	}
	log.Debugf("initial log config: %q", logger.lastConfig)

	w, err := watcher.NewNotifyWorker(watcher.NotifyConfig{
		Handler: logger,
	})
	if err != nil {
		return nil, errors.Trace(err)
	}
	return w, nil
}