MCPcopy
hub / github.com/tuna/tunasync / NewTUNASyncWorker

Function NewTUNASyncWorker

worker/worker.go:31–66  ·  view source on GitHub ↗

NewTUNASyncWorker creates a worker

(cfg *Config)

Source from the content-addressed store, hash-verified

29
30// NewTUNASyncWorker creates a worker
31func NewTUNASyncWorker(cfg *Config) *Worker {
32
33 if cfg.Global.Retry == 0 {
34 cfg.Global.Retry = defaultMaxRetry
35 }
36
37 w := &Worker{
38 cfg: cfg,
39 jobs: make(map[string]*mirrorJob),
40
41 managerChan: make(chan jobMessage, 32),
42 semaphore: make(chan empty, cfg.Global.Concurrent),
43 exit: make(chan empty),
44
45 schedule: newScheduleQueue(),
46 }
47
48 if cfg.Manager.CACert != "" {
49 httpClient, err := CreateHTTPClient(cfg.Manager.CACert)
50 if err != nil {
51 logger.Errorf("Error initializing HTTP client: %s", err.Error())
52 return nil
53 }
54 w.httpClient = httpClient
55 }
56
57 if cfg.Cgroup.Enable {
58 if err := initCgroup(&cfg.Cgroup); err != nil {
59 logger.Errorf("Error initializing Cgroup: %s", err.Error())
60 return nil
61 }
62 }
63 w.initJobs()
64 w.makeHTTPServer()
65 return w
66}
67
68// Run runs worker forever
69func (w *Worker) Run() {

Callers 2

startWorkerFunction · 0.92
startWorkerThenStopFunction · 0.85

Calls 7

initJobsMethod · 0.95
makeHTTPServerMethod · 0.95
newScheduleQueueFunction · 0.85
CreateHTTPClientFunction · 0.85
initCgroupFunction · 0.85
ErrorfMethod · 0.80
ErrorMethod · 0.80

Tested by 1

startWorkerThenStopFunction · 0.68