Skip to content

Commit a3bab29

Browse files
committed
feat(email): add new email service protocol
Signed-off-by: Chayan Das <[email protected]>
1 parent a8ceaf1 commit a3bab29

File tree

2 files changed

+4
-8
lines changed

2 files changed

+4
-8
lines changed

pkg/email/admin.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,8 @@ func FetchAdminEmails() ([]string, error) {
1313
admin := "ADMIN"
1414
err := db.DB.
1515
Model(&models.User{}).
16-
Where(&models.User{UserLevel: &admin}).
16+
Where(&models.User{UserLevel: &admin}). // can add super_admin too
1717
Pluck("user_email", &emails).Error
18-
1918
if err != nil {
2019
return nil, err
2120
}

pkg/email/email_service.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,14 @@ type EmailService interface {
3535

3636
type AsyncEmailService struct {
3737
queue chan EmailData
38-
from string // From address shown in emails
39-
user string // SMTP username (may differ from from)
38+
from string
39+
user string
4040
pass string
4141
host string
4242
port int
4343
logger *zap.Logger
4444
wg sync.WaitGroup
45-
mu sync.Mutex // protects running/closed
45+
mu sync.Mutex
4646
running bool
4747
closed bool
4848

@@ -209,16 +209,13 @@ func (s *AsyncEmailService) doSend(job EmailData) error {
209209
}
210210
}
211211

212-
// ctx allows timeout for shutdown.
213212
func (s *AsyncEmailService) Stop(ctx context.Context) error {
214213
s.mu.Lock()
215214
if s.closed {
216215
s.mu.Unlock()
217216
return nil
218217
}
219-
// mark closed so Queue() returns error
220218
s.closed = true
221-
// close queue to signal workers to finish
222219
close(s.queue)
223220
s.mu.Unlock()
224221

0 commit comments

Comments
 (0)