Skip to content

Commit

Permalink
Merge pull request #12 from openmsupply/#4-attach-report-to-email
Browse files Browse the repository at this point in the history
  • Loading branch information
josh-griffin authored Nov 3, 2020
2 parents d12dc46 + 08f2c95 commit 3c7b0b4
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 13 deletions.
2 changes: 0 additions & 2 deletions backend/pkg/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ func main() {

serveOptions, sqliteDatasource := getServeOptions()

createReports()

c := cron.New()
c.AddFunc("@every 30s", getScheduler(sqliteDatasource))
c.Start()
Expand Down
14 changes: 3 additions & 11 deletions backend/pkg/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,6 @@ type EmailConfig struct {
password string
}

type SmtpServer struct {
host string
port string
}

func (smtpServer *SmtpServer) Address() string {
return smtpServer.host + ":" + smtpServer.port
}

// Possibly take the email config, an attachment and some array of recipients?
func sendEmail() {

Expand All @@ -33,7 +24,7 @@ func sendEmail() {
// // TODO: Subject, message to be added to datasource config? Or schedule config?
m.SetHeader("Subject", "Hello!")
m.SetBody("text/html", "Hello")
// m.Attach("lolcat.jpg")
m.Attach("./data/Book1.xlsx")

// // I don't really know what I'm doing with this auth.
// // PlainAuth works and reading the docs it seems to fail
Expand Down Expand Up @@ -102,7 +93,7 @@ func createReports() {
// { {scheduleID}: excelFilePath }

// f := excelize.NewFile()
f, e := excelize.OpenFile("test.xlsx")
f, e := excelize.OpenFile("./data/test.xlsx")

if e != nil {
log.DefaultLogger.Error("erorr opening", e.Error())
Expand Down Expand Up @@ -149,6 +140,7 @@ func cleanup() {
func getScheduler(sqlite *SQLiteDatasource) func() {
return func() {
log.DefaultLogger.Info("Scheduler!")
createReports()
sendEmail()
log.DefaultLogger.Info("Scheduler2!")

Expand Down

0 comments on commit 3c7b0b4

Please # to comment.