From 7eb119b892701860f2265cd58788f67b0f07fe27 Mon Sep 17 00:00:00 2001 From: zyx Date: Thu, 11 Apr 2019 10:06:21 +0800 Subject: [PATCH] singleton of worker is not used, so remove it --- cmd/tunasync/tunasync.go | 2 +- worker/worker.go | 10 ++-------- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/cmd/tunasync/tunasync.go b/cmd/tunasync/tunasync.go index 9e1ec41..9e67836 100644 --- a/cmd/tunasync/tunasync.go +++ b/cmd/tunasync/tunasync.go @@ -60,7 +60,7 @@ func startWorker(c *cli.Context) error { os.Exit(1) } - w := worker.GetTUNASyncWorker(cfg) + w := worker.NewTUNASyncWorker(cfg) if w == nil { logger.Errorf("Error intializing TUNA sync worker.") os.Exit(1) diff --git a/worker/worker.go b/worker/worker.go index 99f8c2d..321bbc5 100644 --- a/worker/worker.go +++ b/worker/worker.go @@ -12,8 +12,6 @@ import ( . "github.com/tuna/tunasync/internal" ) -var tunasyncWorker *Worker - // A Worker is a instance of tunasync worker type Worker struct { L sync.Mutex @@ -29,11 +27,8 @@ type Worker struct { httpClient *http.Client } -// GetTUNASyncWorker returns a singalton worker -func GetTUNASyncWorker(cfg *Config) *Worker { - if tunasyncWorker != nil { - return tunasyncWorker - } +// NewTUNASyncWorker creates a worker +func NewTUNASyncWorker(cfg *Config) *Worker { w := &Worker{ cfg: cfg, @@ -57,7 +52,6 @@ func GetTUNASyncWorker(cfg *Config) *Worker { w.initJobs() w.makeHTTPServer() - tunasyncWorker = w return w }