Skip to content

Commit

Permalink
MM-57120: delay monitoring job on startup (#570)
Browse files Browse the repository at this point in the history
Delay the monitoring job by at least 1 minute after startup to avoid a race where the plugin hasn't fully yet deployed in a mostly disabled environment.

```
{
  "timestamp": "2024-03-30 15:06:00.011 -03:00",
  "level": "info",
  "msg": "Delaying the Monitoring System Job until at least 1 minute after startup",
  "caller": "app/plugin_api.go:1004",
  "plugin_id": "com.mattermost.msteams-sync"
}

{
  "timestamp": "2024-03-30 15:07:00.016 -03:00",
  "level": "info",
  "msg": "Running the Monitoring System Job",
  "caller": "app/plugin_api.go:1004",
  "plugin_id": "com.mattermost.msteams-sync"
}
```

Fixes: https://mattermost.atlassian.net/browse/MM-57120
  • Loading branch information
lieut-data authored Apr 1, 2024
1 parent b89b19c commit 6280a88
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions server/monitor/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ type Monitor struct {
certificate string
useEvaluationAPI bool
syncDirectMessages bool
startupTime time.Time
}

// New creates a new instance of the Monitor job.
Expand All @@ -44,6 +45,7 @@ func New(client msteams.Client, store store.Store, api plugin.API, metrics metri
useEvaluationAPI: useEvaluationAPI,
certificate: certificate,
syncDirectMessages: syncDirectMessages,
startupTime: time.Now(),
}
}

Expand Down Expand Up @@ -81,6 +83,12 @@ func (m *Monitor) Stop() {
// runMonitoringSystemJob is a callback to trigger the business logic of the Monitor job, being run
// automatically by the job subsystem.
func (m *Monitor) runMonitoringSystemJob() {
// Wait at least one minute after startup before starting the monitoring job.
if time.Since(m.startupTime) < 1*time.Minute {
m.api.LogInfo("Delaying the Monitoring System Job until at least 1 minute after startup")
return
}

defer func() {
if r := recover(); r != nil {
m.metrics.ObserveGoroutineFailure()
Expand Down

0 comments on commit 6280a88

Please sign in to comment.