Skip to content

Commit

Permalink
Move mailer into services package
Browse files Browse the repository at this point in the history
  • Loading branch information
Aadesh-Baral committed Aug 25, 2022
1 parent afbe6f3 commit 3a28f5f
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 20 deletions.
6 changes: 3 additions & 3 deletions backend/server/api/workerpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"net/http"
"os/exec"

Mailer "github.com/baato/before-after/mailer"
"github.com/baato/before-after/services"
"github.com/gin-gonic/gin"
)

Expand Down Expand Up @@ -75,9 +75,9 @@ func (w Worker) start() {
// Dispatcher has added a job to my jobQueue.
var jobstatus JobStatus = provision(job.Year, job.Bbox, job.Style, job.Name, job.Uuid, job.Country, job.Continent, job.FullName, job.Email)
if jobstatus.status == "done" {
Mailer.SendSuccessMail(job.Email, job.FullName, job.Uuid, job.Name)
services.SendSuccessMail(job.Email, job.FullName, job.Uuid, job.Name)
} else if jobstatus.status == "error" {
Mailer.SendErrorMail(job.Email, job.FullName, job.Uuid, jobstatus.err, job.Year, job.Bbox, job.Name, job.Country, job.Continent, job.Email)
services.SendErrorMail(job.Email, job.FullName, job.Uuid, jobstatus.err, job.Year, job.Bbox, job.Name, job.Country, job.Continent, job.Email)
}

case <-w.quitChan:
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package mailer
package services

import (
"bytes"
Expand All @@ -7,22 +7,8 @@ import (
"net/smtp"
"os"
"text/template"

"github.com/baato/before-after/util"
)

var (
config util.Config
configErr error
)

func init() {
config, configErr = util.LoadConfig("../../")
if configErr != nil {
log.Fatal("cannot load config:", configErr)
}
}

func sendMail(receiver []string, body bytes.Buffer) {
var smtpAuth = smtp.PlainAuth("", config.SMTPUsername, config.SMTPPassword, config.SMTPHost)
var smtpURL = config.SMTPHost + ":" + config.SMTPPort
Expand All @@ -36,7 +22,7 @@ func SendSuccessMail(receiver string, FullName string, Uuid string, Name string)
if err != nil {
log.Fatal(err)
}
t, err := template.ParseFiles(wd + "/mailer/email-template.html")
t, err := template.ParseFiles(wd + "/services/email_templates/email-template.html")
if err != nil {
fmt.Println(err)
}
Expand All @@ -63,7 +49,7 @@ func SendErrorMail(receiver string, FullName, Uuid, ErrorAt, Year, Bbox, Name, C
if err != nil {
log.Fatal(err)
}
t, err := template.ParseFiles(wd + "/mailer/error-email-template.html")
t, err := template.ParseFiles(wd + "/services/email_templates/error-email-template.html")
if err != nil {
fmt.Println(err)
}
Expand Down

0 comments on commit 3a28f5f

Please sign in to comment.