2021-01-31 10:01:03 +01:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
2021-02-05 10:04:19 +01:00
|
|
|
"strconv"
|
2021-01-31 10:01:03 +01:00
|
|
|
|
2021-05-13 08:15:14 +02:00
|
|
|
"git.ewintr.nl/go-kit/log"
|
|
|
|
"git.ewintr.nl/gte/internal/process"
|
2021-05-13 09:47:06 +02:00
|
|
|
"git.ewintr.nl/gte/internal/task"
|
2021-05-13 08:15:14 +02:00
|
|
|
"git.ewintr.nl/gte/pkg/msend"
|
2021-05-13 09:47:06 +02:00
|
|
|
"git.ewintr.nl/gte/pkg/mstore"
|
2021-01-31 10:01:03 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2021-05-13 08:15:14 +02:00
|
|
|
logger := log.New(os.Stdout).WithField("cmd", "generate-recurring")
|
|
|
|
IMAPConfig := &mstore.IMAPConfig{
|
|
|
|
IMAPURL: os.Getenv("IMAP_URL"),
|
|
|
|
IMAPUsername: os.Getenv("IMAP_USERNAME"),
|
|
|
|
IMAPPassword: os.Getenv("IMAP_PASSWORD"),
|
2021-01-31 10:01:03 +01:00
|
|
|
}
|
2021-05-13 08:15:14 +02:00
|
|
|
msgStore := mstore.NewIMAP(IMAPConfig)
|
|
|
|
|
|
|
|
SMTPConfig := &msend.SSLSMTPConfig{
|
|
|
|
URL: os.Getenv("SMTP_URL"),
|
|
|
|
Username: os.Getenv("SMTP_USERNAME"),
|
|
|
|
Password: os.Getenv("SMTP_PASSWORD"),
|
|
|
|
From: os.Getenv("SMTP_FROM"),
|
|
|
|
To: os.Getenv("SMTP_TO"),
|
|
|
|
}
|
|
|
|
if !SMTPConfig.Valid() {
|
|
|
|
logger.Error("please set SMTP_URL, SMTP_USERNAME, etc environment variables")
|
|
|
|
os.Exit(1)
|
2021-01-31 10:01:03 +01:00
|
|
|
}
|
2021-05-13 08:15:14 +02:00
|
|
|
mailSend := msend.NewSSLSMTP(SMTPConfig)
|
|
|
|
|
2021-02-05 10:04:19 +01:00
|
|
|
daysAhead, err := strconv.Atoi(os.Getenv("GTE_DAYS_AHEAD"))
|
|
|
|
if err != nil {
|
|
|
|
daysAhead = 0
|
|
|
|
}
|
2021-01-31 10:01:03 +01:00
|
|
|
|
2021-05-13 08:15:14 +02:00
|
|
|
taskRepo := task.NewRepository(msgStore)
|
|
|
|
taskDisp := task.NewDispatcher(mailSend)
|
2021-01-31 10:01:03 +01:00
|
|
|
|
2021-05-13 08:15:14 +02:00
|
|
|
recur := process.NewRecur(taskRepo, taskDisp, daysAhead)
|
|
|
|
result, err := recur.Process()
|
2021-01-31 10:01:03 +01:00
|
|
|
if err != nil {
|
2021-05-13 08:15:14 +02:00
|
|
|
logger.WithErr(err).Error("unable to process recurring")
|
|
|
|
os.Exit(1)
|
2021-01-31 10:01:03 +01:00
|
|
|
}
|
|
|
|
|
2021-05-13 08:15:14 +02:00
|
|
|
logger.WithField("count", result.Count).Info("finished generating recurring tasks")
|
2021-01-31 10:01:03 +01:00
|
|
|
}
|