diff options
author | Corey Hulen <corey@hulen.com> | 2017-09-25 13:30:33 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-09-25 13:30:33 -0700 |
commit | 81c18a01bd22437457da04b6cdb8d409beb54446 (patch) | |
tree | 1c1a28dc72fe8685259870e53643de9f558dad79 /jobs/jobs_watcher.go | |
parent | 1bf2a2e8d5a552d23e16379e73c2d4aaefc9368f (diff) | |
download | chat-81c18a01bd22437457da04b6cdb8d409beb54446.tar.gz chat-81c18a01bd22437457da04b6cdb8d409beb54446.tar.bz2 chat-81c18a01bd22437457da04b6cdb8d409beb54446.zip |
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
Diffstat (limited to 'jobs/jobs_watcher.go')
-rw-r--r-- | jobs/jobs_watcher.go | 27 |
1 files changed, 18 insertions, 9 deletions
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: + } + } } } } |