// NewNotifyWorker starts a new worker running the business logic from
// the handler. The worker loop is started in another goroutine as a
// side effect of calling this.
965914
func NewNotifyWorker(handler NotifyWatchHandler) worker.Worker {
	nw := &notifyWorker{
		handler: handler,
	}

	nw.tomb.Go(nw.loop)
	return nw
}
545134
func NewCeleryWorker(broker CeleryBroker, backend CeleryBackend, numWorkers int) *CeleryWorker {
	return &CeleryWorker{
		broker:          broker,
		backend:         backend,
		numWorkers:      numWorkers,
		registeredTasks: map[string]interface{}{},
		rateLimitPeriod: 100 * time.Millisecond,
	}
}
419708
func NewWorker() worker.Worker {
	var w terminationWorker
	c := make(chan os.Signal, 1)
	signal.Notify(c, TerminationSignal)
	w.tomb.Go(func() error {
		defer signal.Stop(c)
		return w.loop(c)
	})
	return &w
}
1299000
func NewWorker(opt WorkerOpt) (*Worker, error) {
	imageRefChecker := imagerefchecker.New(imagerefchecker.Opt{
		ImageStore:   opt.ImageStore,
		Snapshotter:  opt.Snapshotter,
		ContentStore: opt.ContentStore,
	})

	cm, err := cache.NewManager(cache.ManagerOpt{
		Snapshotter:     opt.Snapshotter,
		MetadataStore:   opt.MetadataStore,
		PruneRefChecker: imageRefChecker,
	})
	if err != nil {
		return nil, err
	}

	sm, err := source.NewManager()
	if err != nil {
		return nil, err
	}

	is, err := containerimage.NewSource(containerimage.SourceOpt{
		Snapshotter:   opt.Snapshotter,
		ContentStore:  opt.ContentStore,
		Applier:       opt.Applier,
		ImageStore:    opt.ImageStore,
		CacheAccessor: cm,
		ResolverOpt:   opt.ResolveOptionsFunc,
	})
	if err != nil {
		return nil, err
	}

	sm.Register(is)

	if err := git.Supported(); err == nil {
		gs, err := git.NewSource(git.Opt{
			CacheAccessor: cm,
			MetadataStore: opt.MetadataStore,
		})
		if err != nil {
			return nil, err
		}
		sm.Register(gs)
	} else {
		logrus.Warnf("git source cannot be enabled: %v", err)
	}

	hs, err := http.NewSource(http.Opt{
		CacheAccessor: cm,
		MetadataStore: opt.MetadataStore,
	})
	if err != nil {
		return nil, err
	}

	sm.Register(hs)

	ss, err := local.NewSource(local.Opt{
		CacheAccessor: cm,
		MetadataStore: opt.MetadataStore,
	})
	if err != nil {
		return nil, err
	}
	sm.Register(ss)

	iw, err := imageexporter.NewImageWriter(imageexporter.WriterOpt{
		Snapshotter:  opt.Snapshotter,
		ContentStore: opt.ContentStore,
		Applier:      opt.Applier,
		Differ:       opt.Differ,
	})
	if err != nil {
		return nil, err
	}

	return &Worker{
		WorkerOpt:     opt,
		CacheManager:  cm,
		SourceManager: sm,
		imageWriter:   iw,
		ImageSource:   is,
	}, nil
}
905248
func newWorker(id int,
	pluginQueue chan PluginRequest,
	taskQueue chan TaskRequest,
	quitChan chan struct{},
	wg *sync.WaitGroup,
	pm ManagesPlugins,
	tm ManagesTasks,
	mm getsMembers) worker {
	logger := log.WithFields(log.Fields{
		"_module":   "worker",
		"worker-id": id,
	})
	worker := worker{
		pluginManager: pm,
		taskManager:   tm,
		memberManager: mm,
		id:            id,
		pluginWork:    pluginQueue,
		taskWork:      taskQueue,
		waitGroup:     wg,
		quitChan:      quitChan,
		logger:        logger,
	}

	return worker
}
1092071
func NewWorker(config *config.Config) (*Worker, error) {
	hostname, err := os.Hostname()
	if err != nil {
		return nil, err
	}

	workers.Configure(map[string]string{
		"server":   config.GetString("pitaya.worker.redis.url"),
		"pool":     config.GetString("pitaya.worker.redis.pool"),
		"password": config.GetString("pitaya.worker.redis.password"),
		"process":  hostname,
	})

	return &Worker{
		concurrency: config.GetInt("pitaya.worker.concurrency"),
		opts:        NewEnqueueOpts(config),
		config:      config,
	}, nil
}
200979
func NewWorker(
	algorithm pruneAlgorithm,
	registryClientFactory RegistryClientFactoryFunc,
	registryURL *url.URL,
	imagePrunerFactory ImagePrunerFactoryFunc,
	streamPruner ImageStreamDeleter,
	layerLinkPruner LayerLinkDeleter,
	blobPruner BlobDeleter,
	manifestPruner ManifestDeleter,
) (Worker, error) {
	client, err := registryClientFactory()
	if err != nil {
		return nil, err
	}

	imagePruner, err := imagePrunerFactory()
	if err != nil {
		return nil, err
	}

	return &worker{
		algorithm:       algorithm,
		registryClient:  client,
		registryURL:     registryURL,
		imagePruner:     imagePruner,
		streamPruner:    streamPruner,
		layerLinkPruner: layerLinkPruner,
		blobPruner:      blobPruner,
		manifestPruner:  manifestPruner,
	}, nil
}
933222
func (server *Server) NewWorker(consumerTag string, concurrency int) *Worker {
	return &Worker{
		server:      server,
		ConsumerTag: consumerTag,
		Concurrency: concurrency,
		Queue:       "",
	}
}
1286432
func StartWorker(config *config.Config) error {
	var err error
	app.worker, err = worker.NewWorker(config)
	if err != nil {
		return err
	}

	app.worker.Start()

	return nil
}
231477
func NewNotifier(send func([]byte) (int, error)) Notifier {
	n := &notifier{}
	n.ctx, n.cancel = context.WithCancel(context.Background())
	n.send = send
	// n.maxlen = cap
	return n
}
947419
func InitWorkers(workerNum int64, queueNum int64) {
	LogAccess.Debug("worker number is ", workerNum, ", queue number is ", queueNum)
	QueueNotification = make(chan PushNotification, queueNum)
	for i := int64(0); i < workerNum; i++ {
		go startWorker()
	}
}
517497
func NewWorkitemController(service *goa.Service, db application.DB, config WorkItemControllerConfig) *WorkitemController {
	return NewNotifyingWorkitemController(service, db, &notification.DevNullChannel{}, config)
}
67407
func NewPanicWorker(wr *wrangler.Wrangler) (Worker, error) {
	return &PanicWorker{
		StatusWorker: NewStatusWorker(),
		wr:           wr,
	}, nil
}
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
}
224928
func NewPeriodicWorker(do jworker.PeriodicWorkerCall, period time.Duration, newTimer func(time.Duration) jworker.PeriodicTimer, stop func()) worker.Worker {
	return &periodicWorker{
		Worker: jworker.NewPeriodicWorker(do, period, newTimer, jworker.Jitter(0.2)),
		stop:   stop,
	}
}
1069967
func newWorker(a agent.Agent, apiCaller base.APICaller) (worker.Worker, error) {
	currentConfig := a.CurrentConfig()

	// TODO(fwereade): this functionality should be on the
	// machiner facade instead -- or, better yet, separate
	// the networking concerns from the lifecycle ones and
	// have completely separate workers.
	//
	// (With their own facades.)
	agentFacade, err := apiagent.NewState(apiCaller)
	if err != nil {
		return nil, errors.Trace(err)
	}
	modelConfig, err := agentFacade.ModelConfig()
	if err != nil {
		return nil, errors.Errorf("cannot read environment config: %v", err)
	}

	ignoreMachineAddresses, _ := modelConfig.IgnoreMachineAddresses()
	// Containers only have machine addresses, so we can't ignore them.
	tag := currentConfig.Tag()
	if names.IsContainerMachine(tag.Id()) {
		ignoreMachineAddresses = false
	}
	if ignoreMachineAddresses {
		logger.Infof("machine addresses not used, only addresses from provider")
	}
	accessor := APIMachineAccessor{apimachiner.NewState(apiCaller)}
	w, err := NewMachiner(Config{
		MachineAccessor:              accessor,
		Tag:                          tag.(names.MachineTag),
		ClearMachineAddressesOnStart: ignoreMachineAddresses,
		NotifyMachineDead: func() error {
			return agent.SetCanUninstall(a)
		},
	})
	if err != nil {
		return nil, errors.Annotate(err, "cannot start machiner worker")
	}
	return w, err
}
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")
}