From 4e79d2d4d037e7c33ec3e63d58110668106de222 Mon Sep 17 00:00:00 2001 From: Chris Date: Fri, 29 Sep 2017 04:29:29 -0500 Subject: remove jobs.Srv and other jobs-related globals (#7535) --- app/admin.go | 3 +-- app/app.go | 45 ++++++++++++++++++++++++++++++++++++++++++++- app/job.go | 9 ++++----- 3 files changed, 49 insertions(+), 8 deletions(-) (limited to 'app') diff --git a/app/admin.go b/app/admin.go index 0d02c3b49..dab7e9759 100644 --- a/app/admin.go +++ b/app/admin.go @@ -14,7 +14,6 @@ import ( "net/http" l4g "github.com/alecthomas/log4go" - "github.com/mattermost/mattermost-server/jobs" "github.com/mattermost/mattermost-server/model" "github.com/mattermost/mattermost-server/store" "github.com/mattermost/mattermost-server/store/sqlstore" @@ -190,7 +189,7 @@ func (a *App) RecycleDatabaseConnection() { l4g.Warn(utils.T("api.admin.recycle_db_start.warn")) a.Srv.Store = store.NewLayeredStore(sqlstore.NewSqlSupplier(a.Metrics), a.Metrics, a.Cluster) - jobs.Srv.Store = a.Srv.Store + a.Jobs.Store = a.Srv.Store time.Sleep(20 * time.Second) oldStore.Close() diff --git a/app/app.go b/app/app.go index e85fa6342..26388d841 100644 --- a/app/app.go +++ b/app/app.go @@ -9,6 +9,8 @@ import ( "sync" "github.com/mattermost/mattermost-server/einterfaces" + ejobs "github.com/mattermost/mattermost-server/einterfaces/jobs" + "github.com/mattermost/mattermost-server/jobs" "github.com/mattermost/mattermost-server/model" "github.com/mattermost/mattermost-server/plugin/pluginenv" "github.com/mattermost/mattermost-server/utils" @@ -25,6 +27,8 @@ type App struct { Hubs []*Hub HubsStopCheckingForDeadlock chan bool + Jobs *jobs.JobServer + AccountMigration einterfaces.AccountMigrationInterface Brand einterfaces.BrandInterface Cluster einterfaces.ClusterInterface @@ -36,7 +40,9 @@ type App struct { Saml einterfaces.SamlInterface } -var globalApp App +var globalApp App = App{ + Jobs: &jobs.JobServer{}, +} var initEnterprise sync.Once @@ -65,6 +71,30 @@ func RegisterComplianceInterface(f func(*App) einterfaces.ComplianceInterface) { complianceInterface = f } +var jobsDataRetentionInterface func(*App) ejobs.DataRetentionInterface + +func RegisterJobsDataRetentionInterface(f func(*App) ejobs.DataRetentionInterface) { + jobsDataRetentionInterface = f +} + +var jobsElasticsearchAggregatorInterface func(*App) ejobs.ElasticsearchAggregatorInterface + +func RegisterJobsElasticsearchAggregatorInterface(f func(*App) ejobs.ElasticsearchAggregatorInterface) { + jobsElasticsearchAggregatorInterface = f +} + +var jobsElasticsearchIndexerInterface func(*App) ejobs.ElasticsearchIndexerInterface + +func RegisterJobsElasticsearchIndexerInterface(f func(*App) ejobs.ElasticsearchIndexerInterface) { + jobsElasticsearchIndexerInterface = f +} + +var jobsLdapSyncInterface func(*App) ejobs.LdapSyncInterface + +func RegisterJobsLdapSyncInterface(f func(*App) ejobs.LdapSyncInterface) { + jobsLdapSyncInterface = f +} + var ldapInterface func(*App) einterfaces.LdapInterface func RegisterLdapInterface(f func(*App) einterfaces.LdapInterface) { @@ -121,6 +151,19 @@ func (a *App) initEnterprise() { a.Saml.ConfigureSP() }) } + + if jobsDataRetentionInterface != nil { + a.Jobs.DataRetention = jobsDataRetentionInterface(a) + } + if jobsElasticsearchAggregatorInterface != nil { + a.Jobs.ElasticsearchAggregator = jobsElasticsearchAggregatorInterface(a) + } + if jobsElasticsearchIndexerInterface != nil { + a.Jobs.ElasticsearchIndexer = jobsElasticsearchIndexerInterface(a) + } + if jobsLdapSyncInterface != nil { + a.Jobs.LdapSync = jobsLdapSyncInterface(a) + } } func (a *App) Config() *model.Config { diff --git a/app/job.go b/app/job.go index c1058880f..d80fe6262 100644 --- a/app/job.go +++ b/app/job.go @@ -4,7 +4,6 @@ package app import ( - "github.com/mattermost/mattermost-server/jobs" "github.com/mattermost/mattermost-server/model" ) @@ -40,10 +39,10 @@ func (a *App) GetJobsByType(jobType string, offset int, limit int) ([]*model.Job } } -func CreateJob(job *model.Job) (*model.Job, *model.AppError) { - return jobs.CreateJob(job.Type, job.Data) +func (a *App) CreateJob(job *model.Job) (*model.Job, *model.AppError) { + return a.Jobs.CreateJob(job.Type, job.Data) } -func CancelJob(jobId string) *model.AppError { - return jobs.RequestCancellation(jobId) +func (a *App) CancelJob(jobId string) *model.AppError { + return a.Jobs.RequestCancellation(jobId) } -- cgit v1.2.3-1-g7c22