From 0d05fe32af26d881b205b9f57b32fb1883791d37 Mon Sep 17 00:00:00 2001 From: Jesse Hallam Date: Fri, 5 Jul 2019 20:11:11 -0300 Subject: [PATCH] MM-16796: reduce plugin job interval to once per day (#11521) * MM-16796: reduce plugin job interval to once per day The Jobs infrastructure isn't currently setup for running frequent jobs, as it spams the Jobs table with useless records. Update the plugin job interval to run less frequently -- since the cleanup doesn't affect semantics anyway -- and clean up the previously created entries in the Jobs table. --- plugin/scheduler/scheduler.go | 4 +++- store/sqlstore/upgrade.go | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/plugin/scheduler/scheduler.go b/plugin/scheduler/scheduler.go index fade4fdc17..685b073106 100644 --- a/plugin/scheduler/scheduler.go +++ b/plugin/scheduler/scheduler.go @@ -11,6 +11,8 @@ import ( "github.com/mattermost/mattermost-server/model" ) +const pluginsJobInterval = 24 * 60 * 60 * time.Second + type Scheduler struct { App *app.App } @@ -32,7 +34,7 @@ func (scheduler *Scheduler) Enabled(cfg *model.Config) bool { } func (scheduler *Scheduler) NextScheduleTime(cfg *model.Config, now time.Time, pendingJobs bool, lastSuccessfulJob *model.Job) *time.Time { - nextTime := time.Now().Add(60 * time.Second) + nextTime := time.Now().Add(pluginsJobInterval) return &nextTime } diff --git a/store/sqlstore/upgrade.go b/store/sqlstore/upgrade.go index 6e89653e98..fc55ae6234 100644 --- a/store/sqlstore/upgrade.go +++ b/store/sqlstore/upgrade.go @@ -699,6 +699,9 @@ func UpgradeDatabaseToVersion512(sqlStore SqlStore) { func UpgradeDatabaseToVersion513(sqlStore SqlStore) { if shouldPerformUpgrade(sqlStore, VERSION_5_12_0, VERSION_5_13_0) { + // The previous jobs ran once per minute, cluttering the Jobs table with somewhat useless entries. Clean that up. + sqlStore.GetMaster().Exec("DELETE FROM Jobs WHERE Type = 'plugins'") + saveSchemaVersion(sqlStore, VERSION_5_13_0) } }