From 83d53ea98cf5486f89bd4280b6b5ef835da4fd22 Mon Sep 17 00:00:00 2001 From: George Goldberg Date: Tue, 11 Jul 2017 09:09:15 +0100 Subject: PLT-6475: Elasticsearch Indexing Worker. (#6879) --- jobs/workers.go | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) (limited to 'jobs/workers.go') diff --git a/jobs/workers.go b/jobs/workers.go index a42ec4607..bb80ad79a 100644 --- a/jobs/workers.go +++ b/jobs/workers.go @@ -13,13 +13,13 @@ import ( ) type Workers struct { - startOnce sync.Once - watcher *Watcher + startOnce sync.Once + watcher *Watcher - DataRetention model.Worker - // SearchIndexing model.Job + DataRetention model.Worker + ElasticsearchIndexing model.Worker - listenerId string + listenerId string } func InitWorkers() *Workers { @@ -32,6 +32,10 @@ func InitWorkers() *Workers { workers.DataRetention = dataRetentionInterface.MakeWorker() } + if elasticsearchIndexerInterface := ejobs.GetElasticsearchIndexerInterface(); elasticsearchIndexerInterface != nil { + workers.ElasticsearchIndexing = elasticsearchIndexerInterface.MakeWorker() + } + return workers } @@ -43,7 +47,9 @@ func (workers *Workers) Start() *Workers { go workers.DataRetention.Run() } - // go workers.SearchIndexing.Run() + if workers.ElasticsearchIndexing != nil && *utils.Cfg.ElasticSearchSettings.EnableIndexing { + go workers.ElasticsearchIndexing.Run() + } go workers.watcher.Start() }) @@ -61,6 +67,14 @@ func (workers *Workers) handleConfigChange(oldConfig *model.Config, newConfig *m workers.DataRetention.Stop() } } + + if workers.ElasticsearchIndexing != nil { + if !*oldConfig.ElasticSearchSettings.EnableIndexing && *newConfig.ElasticSearchSettings.EnableIndexing { + go workers.ElasticsearchIndexing.Run() + } else if *oldConfig.ElasticSearchSettings.EnableIndexing && !*newConfig.ElasticSearchSettings.EnableIndexing { + workers.ElasticsearchIndexing.Stop() + } + } } func (workers *Workers) Stop() *Workers { @@ -71,7 +85,10 @@ func (workers *Workers) Stop() *Workers { if workers.DataRetention != nil && *utils.Cfg.DataRetentionSettings.Enable { workers.DataRetention.Stop() } - // workers.SearchIndexing.Stop() + + if workers.ElasticsearchIndexing != nil && *utils.Cfg.ElasticSearchSettings.EnableIndexing { + workers.ElasticsearchIndexing.Stop() + } l4g.Info("Stopped workers") -- cgit v1.2.3-1-g7c22