summaryrefslogtreecommitdiffstats
path: root/app/email_batching.go
diff options
context:
space:
mode:
authorChris <ccbrown112@gmail.com>2017-09-27 11:52:34 -0500
committerSaturnino Abril <saturnino.abril@gmail.com>2017-09-28 00:52:34 +0800
commit8c80cdde38cceb3424b2b1f43eadf7a1aab0c6df (patch)
treeb3563dfe35ad78991774c9d1842dc439376e1db1 /app/email_batching.go
parent1bd66589a2adc67df5df9c108a2f2ecc77dfdf44 (diff)
downloadchat-8c80cdde38cceb3424b2b1f43eadf7a1aab0c6df.tar.gz
chat-8c80cdde38cceb3424b2b1f43eadf7a1aab0c6df.tar.bz2
chat-8c80cdde38cceb3424b2b1f43eadf7a1aab0c6df.zip
remove remaining Global() calls (outside of tests) (#7521)
Diffstat (limited to 'app/email_batching.go')
-rw-r--r--app/email_batching.go26
1 files changed, 13 insertions, 13 deletions
diff --git a/app/email_batching.go b/app/email_batching.go
index c8ea8c98a..b9f89d646 100644
--- a/app/email_batching.go
+++ b/app/email_batching.go
@@ -22,26 +22,24 @@ const (
EMAIL_BATCHING_TASK_NAME = "Email Batching"
)
-var emailBatchingJob *EmailBatchingJob
-
-func InitEmailBatching() {
+func (a *App) InitEmailBatching() {
if *utils.Cfg.EmailSettings.EnableEmailBatching {
- if emailBatchingJob == nil {
- emailBatchingJob = MakeEmailBatchingJob(*utils.Cfg.EmailSettings.EmailBatchingBufferSize)
+ if a.EmailBatching == nil {
+ a.EmailBatching = NewEmailBatchingJob(a, *utils.Cfg.EmailSettings.EmailBatchingBufferSize)
}
// note that we don't support changing EmailBatchingBufferSize without restarting the server
- emailBatchingJob.Start()
+ a.EmailBatching.Start()
}
}
-func AddNotificationEmailToBatch(user *model.User, post *model.Post, team *model.Team) *model.AppError {
+func (a *App) AddNotificationEmailToBatch(user *model.User, post *model.Post, team *model.Team) *model.AppError {
if !*utils.Cfg.EmailSettings.EnableEmailBatching {
return model.NewAppError("AddNotificationEmailToBatch", "api.email_batching.add_notification_email_to_batch.disabled.app_error", nil, "", http.StatusNotImplemented)
}
- if !emailBatchingJob.Add(user, post, team) {
+ if !a.EmailBatching.Add(user, post, team) {
l4g.Error(utils.T("api.email_batching.add_notification_email_to_batch.channel_full.app_error"))
return model.NewAppError("AddNotificationEmailToBatch", "api.email_batching.add_notification_email_to_batch.channel_full.app_error", nil, "", http.StatusInternalServerError)
}
@@ -56,12 +54,14 @@ type batchedNotification struct {
}
type EmailBatchingJob struct {
+ app *App
newNotifications chan *batchedNotification
pendingNotifications map[string][]*batchedNotification
}
-func MakeEmailBatchingJob(bufferSize int) *EmailBatchingJob {
+func NewEmailBatchingJob(a *App, bufferSize int) *EmailBatchingJob {
return &EmailBatchingJob{
+ app: a,
newNotifications: make(chan *batchedNotification, bufferSize),
pendingNotifications: make(map[string][]*batchedNotification),
}
@@ -97,7 +97,7 @@ func (job *EmailBatchingJob) CheckPendingEmails() {
// it's a bit weird to pass the send email function through here, but it makes it so that we can test
// without actually sending emails
- job.checkPendingNotifications(time.Now(), Global().sendBatchedEmailNotification)
+ job.checkPendingNotifications(time.Now(), job.app.sendBatchedEmailNotification)
l4g.Debug(utils.T("api.email_batching.check_pending_emails.finished_running"), len(job.pendingNotifications))
}
@@ -131,7 +131,7 @@ func (job *EmailBatchingJob) checkPendingNotifications(now time.Time, handler fu
if inspectedTeamNames[notification.teamName] != "" {
continue
}
- tchan := Global().Srv.Store.Team().GetByName(notifications[0].teamName)
+ tchan := job.app.Srv.Store.Team().GetByName(notifications[0].teamName)
if result := <-tchan; result.Err != nil {
l4g.Error("Unable to find Team id for notification", result.Err)
continue
@@ -141,7 +141,7 @@ func (job *EmailBatchingJob) checkPendingNotifications(now time.Time, handler fu
// if the user has viewed any channels in this team since the notification was queued, delete
// all queued notifications
- mchan := Global().Srv.Store.Channel().GetMembersForUser(inspectedTeamNames[notification.teamName], userId)
+ mchan := job.app.Srv.Store.Channel().GetMembersForUser(inspectedTeamNames[notification.teamName], userId)
if result := <-mchan; result.Err != nil {
l4g.Error("Unable to find ChannelMembers for user", result.Err)
continue
@@ -158,7 +158,7 @@ func (job *EmailBatchingJob) checkPendingNotifications(now time.Time, handler fu
// get how long we need to wait to send notifications to the user
var interval int64
- pchan := Global().Srv.Store.Preference().Get(userId, model.PREFERENCE_CATEGORY_NOTIFICATIONS, model.PREFERENCE_NAME_EMAIL_INTERVAL)
+ pchan := job.app.Srv.Store.Preference().Get(userId, model.PREFERENCE_CATEGORY_NOTIFICATIONS, model.PREFERENCE_NAME_EMAIL_INTERVAL)
if result := <-pchan; result.Err != nil {
// use the default batching interval if an error ocurrs while fetching user preferences
interval, _ = strconv.ParseInt(model.PREFERENCE_EMAIL_INTERVAL_BATCHING_SECONDS, 10, 64)