From 0495a519499d6cefa289982a94d8f42de541c1f0 Mon Sep 17 00:00:00 2001 From: George Goldberg Date: Fri, 7 Jul 2017 15:21:02 +0100 Subject: PLT-6916: Redesign the jobs package and Jobserver. (#6733) This commit redesigns the jobserver to be based around an architecture of "workers", which carry out jobs of a particular type, and "jobs" which are a unit of work carried by a particular worker. It also introduces "schedulers" which are responsible for scheduling jobs of a particular type automatically (jobs can also be scheduled manually when apropriate). Workers may be run many times, either in instances of the platform binary, or the standalone jobserver binary. In any mattermost cluster, only one instance of platform OR jobserver must run the schedulers. At the moment this is controlled by a config variable, but in future will be controlled through the cluster leader election process. --- jobs/jobserver/jobserver.go | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'jobs/jobserver/jobserver.go') diff --git a/jobs/jobserver/jobserver.go b/jobs/jobserver/jobserver.go index 5f491a815..aabe5d3b2 100644 --- a/jobs/jobserver/jobserver.go +++ b/jobs/jobserver/jobserver.go @@ -16,22 +16,20 @@ import ( _ "github.com/mattermost/platform/imports" ) -var Srv jobs.JobServer - func main() { // Initialize utils.InitAndLoadConfig("config.json") defer l4g.Close() - Srv.Store = store.NewLayeredStore() - defer Srv.Store.Close() + jobs.Srv.Store = store.NewLayeredStore() + defer jobs.Srv.Store.Close() - Srv.LoadLicense() + jobs.Srv.LoadLicense() // Run jobs l4g.Info("Starting Mattermost job server") - Srv.Jobs = jobs.InitJobs(Srv.Store) - Srv.Jobs.Start() + jobs.Srv.StartWorkers() + jobs.Srv.StartSchedulers() var signalChan chan os.Signal = make(chan os.Signal) signal.Notify(signalChan, os.Interrupt, syscall.SIGINT, syscall.SIGTERM) @@ -40,7 +38,8 @@ func main() { // Cleanup anything that isn't handled by a defer statement l4g.Info("Stopping Mattermost job server") - Srv.Jobs.Stop() + jobs.Srv.StopSchedulers() + jobs.Srv.StopWorkers() l4g.Info("Stopped Mattermost job server") } -- cgit v1.2.3-1-g7c22