Skip to content

Commit

Permalink
style(worker): put exported methods together
Browse files Browse the repository at this point in the history
  • Loading branch information
bigeagle committed May 2, 2016
1 parent 76ad3d4 commit 5b5f020
Showing 1 changed file with 26 additions and 27 deletions.
53 changes: 26 additions & 27 deletions worker/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,26 @@ func GetTUNASyncWorker(cfg *Config) *Worker {
return w
}

func (w *Worker) initJobs() {
for _, mirror := range w.cfg.Mirrors {
// Create Provider
provider := newMirrorProvider(mirror, w.cfg)
w.jobs[provider.Name()] = newMirrorJob(provider)
// Run runs worker forever
func (w *Worker) Run() {
w.registorWorker()
go w.runHTTPServer()
w.runSchedule()
}

// Halt stops all jobs
func (w *Worker) Halt() {
w.L.Lock()
logger.Notice("Stopping all the jobs")
for _, job := range w.jobs {
if job.State() != stateDisabled {
job.ctrlChan <- jobHalt
}
}
jobsDone.Wait()
logger.Notice("All the jobs are stopped")
w.L.Unlock()
close(w.exit)
}

// ReloadMirrorConfig refresh the providers and jobs
Expand Down Expand Up @@ -134,7 +148,14 @@ func (w *Worker) ReloadMirrorConfig(newMirrors []mirrorConfig) {
}

w.cfg.Mirrors = newMirrors
}

func (w *Worker) initJobs() {
for _, mirror := range w.cfg.Mirrors {
// Create Provider
provider := newMirrorProvider(mirror, w.cfg)
w.jobs[provider.Name()] = newMirrorJob(provider)
}
}

func (w *Worker) disableJob(job *mirrorJob) {
Expand Down Expand Up @@ -224,28 +245,6 @@ func (w *Worker) runHTTPServer() {
}
}

// Halt stops all jobs
func (w *Worker) Halt() {
w.L.Lock()
logger.Notice("Stopping all the jobs")
for _, job := range w.jobs {
if job.State() != stateDisabled {
job.ctrlChan <- jobHalt
}
}
jobsDone.Wait()
logger.Notice("All the jobs are stopped")
w.L.Unlock()
close(w.exit)
}

// Run runs worker forever
func (w *Worker) Run() {
w.registorWorker()
go w.runHTTPServer()
w.runSchedule()
}

func (w *Worker) runSchedule() {
w.L.Lock()

Expand Down

0 comments on commit 5b5f020

Please sign in to comment.