53 lines
1.1 KiB
Go
53 lines
1.1 KiB
Go
package app
|
|
|
|
import (
|
|
"context"
|
|
"go.uber.org/zap"
|
|
"mailnotifier/internal/clients"
|
|
"mailnotifier/internal/initialize"
|
|
"mailnotifier/internal/repository"
|
|
"mailnotifier/internal/workers"
|
|
)
|
|
|
|
func Run(ctx context.Context, config initialize.Config, logger *zap.Logger) error {
|
|
mdb, err := initialize.MongoInit(ctx, config)
|
|
if err != nil {
|
|
logger.Error("Failed to initialize MongoDB", zap.Error(err))
|
|
return err
|
|
}
|
|
|
|
kafka, err := initialize.KafkaConsumerInit(ctx, config)
|
|
|
|
repo := repository.NewRepository(mdb.Collection("notify"))
|
|
|
|
mailClient := clients.NewMailClient(clients.Deps{
|
|
SmtpHost: config.SmtpHost,
|
|
SmtpApiUrl: config.SmtpApiUrl,
|
|
SmtpPort: config.SmtpPort,
|
|
SmtpSender: config.SmtpSender,
|
|
Username: config.SmtpUsername,
|
|
Password: config.SmtpPassword,
|
|
ApiKey: config.SmtpApiKey,
|
|
Logger: logger,
|
|
})
|
|
|
|
consumer := workers.NewConsumerWC(workers.ConsumerDeps{
|
|
Repo: repo,
|
|
KafkaClient: kafka,
|
|
})
|
|
|
|
notifyer := workers.NewNotifyer(workers.NotifyerDeps{
|
|
Repo: repo,
|
|
MailClient: mailClient,
|
|
})
|
|
|
|
go consumer.Start(ctx)
|
|
go notifyer.Start(ctx)
|
|
|
|
//todo gracefull showtdown wc
|
|
|
|
<-ctx.Done()
|
|
|
|
return nil
|
|
}
|