From 81c18a01bd22437457da04b6cdb8d409beb54446 Mon Sep 17 00:00:00 2001 From: Corey Hulen Date: Mon, 25 Sep 2017 13:30:33 -0700 Subject: PLT-7542 Converting LDAP sync to the job server (#7452) * PLT-7542 Converting LDAP sync to the job server * Fixing minor issues * Fixing build failure * Translate error message * Translate error message * Translate error message * Translate error message * Fixing merge * Fixing bad merge --- jobs/jobs_watcher.go | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) (limited to 'jobs/jobs_watcher.go') diff --git a/jobs/jobs_watcher.go b/jobs/jobs_watcher.go index 8355fc11d..56cf9eb2e 100644 --- a/jobs/jobs_watcher.go +++ b/jobs/jobs_watcher.go @@ -12,21 +12,23 @@ import ( ) const ( - WATCHER_POLLING_INTERVAL = 15000 + DEFAULT_WATCHER_POLLING_INTERVAL = 15000 ) type Watcher struct { workers *Workers - stop chan bool - stopped chan bool + stop chan bool + stopped chan bool + pollingInterval int } -func MakeWatcher(workers *Workers) *Watcher { +func MakeWatcher(workers *Workers, pollingInterval int) *Watcher { return &Watcher{ - stop: make(chan bool, 1), - stopped: make(chan bool, 1), - workers: workers, + stop: make(chan bool, 1), + stopped: make(chan bool, 1), + pollingInterval: pollingInterval, + workers: workers, } } @@ -36,7 +38,7 @@ func (watcher *Watcher) Start() { // Delay for some random number of milliseconds before starting to ensure that multiple // instances of the jobserver don't poll at a time too close to each other. rand.Seed(time.Now().UTC().UnixNano()) - _ = <-time.After(time.Duration(rand.Intn(WATCHER_POLLING_INTERVAL)) * time.Millisecond) + _ = <-time.After(time.Duration(rand.Intn(watcher.pollingInterval)) * time.Millisecond) defer func() { l4g.Debug("Watcher Finished") @@ -48,7 +50,7 @@ func (watcher *Watcher) Start() { case <-watcher.stop: l4g.Debug("Watcher: Received stop signal") return - case <-time.After(WATCHER_POLLING_INTERVAL * time.Millisecond): + case <-time.After(time.Duration(watcher.pollingInterval) * time.Millisecond): watcher.PollAndNotify() } } @@ -88,6 +90,13 @@ func (watcher *Watcher) PollAndNotify() { default: } } + } else if job.Type == model.JOB_TYPE_LDAP_SYNC { + if watcher.workers.LdapSync != nil { + select { + case watcher.workers.LdapSync.JobChannel() <- *job: + default: + } + } } } } -- cgit v1.2.3-1-g7c22