9
9
"github.com/mattermost/mattermost/server/public/model"
10
10
"github.com/mattermost/mattermost/server/public/plugin"
11
11
"github.com/mattermost/mattermost/server/public/pluginapi"
12
+ "github.com/mattermost/mattermost/server/public/pluginapi/cluster"
12
13
"github.com/mattermost/mattermost/server/public/pluginapi/experimental/bot/poster"
13
14
"github.com/mattermost/mattermost/server/public/pluginapi/experimental/telemetry"
14
15
"github.com/pkg/errors"
@@ -49,7 +50,7 @@ type Plugin struct {
49
50
50
51
oauthBroker * OAuthBroker
51
52
52
- channelRefreshJob * time. Ticker
53
+ channelRefreshJob * cluster. Job
53
54
}
54
55
55
56
func (p * Plugin ) ensurePluginAPIClient () {
@@ -164,13 +165,10 @@ func (p *Plugin) OnActivate() error {
164
165
165
166
// google drive watch api doesn't allow indefinite expiry of watch channels
166
167
// so we need to refresh(close old channel and start new one) them before they get expired
167
- p .channelRefreshJob = time .NewTicker (12 * time .Hour )
168
- go func () {
169
- for range p .channelRefreshJob .C {
170
- p .refreshDriveWatchChannels ()
171
- }
172
- }()
173
-
168
+ p .channelRefreshJob , err = cluster .Schedule (p .API , "refreshDriveWatchChannelsJob" , cluster .MakeWaitForInterval (12 * time .Hour ), p .refreshDriveWatchChannels )
169
+ if err != nil {
170
+ return errors .Wrap (err , "failed to create a scheduled recurring job to refresh watch channels" )
171
+ }
174
172
return nil
175
173
}
176
174
@@ -179,7 +177,9 @@ func (p *Plugin) OnDeactivate() error {
179
177
if err := p .telemetryClient .Close (); err != nil {
180
178
p .client .Log .Warn ("Telemetry client failed to close" , "error" , err .Error ())
181
179
}
182
- p .channelRefreshJob .Stop ()
180
+ if err := p .channelRefreshJob .Close (); err != nil {
181
+ p .client .Log .Warn ("Channel refresh job failed to close" , "error" , err .Error ())
182
+ }
183
183
return nil
184
184
}
185
185
0 commit comments