Refactor init functions for clearer dependency visibility

This commit is contained in:
Kailash Nadh 2020-03-08 15:38:47 +05:30
parent 07856d34a2
commit 8771dc28cb
2 changed files with 15 additions and 15 deletions

26
init.go
View file

@ -157,28 +157,28 @@ func initConstants() *constants {
} }
// initCampaignManager initializes the campaign manager. // initCampaignManager initializes the campaign manager.
func initCampaignManager(app *App) *manager.Manager { func initCampaignManager(q *Queries, cs *constants, app *App) *manager.Manager {
campNotifCB := func(subject string, data interface{}) error { campNotifCB := func(subject string, data interface{}) error {
return app.sendNotification(app.constants.NotifyEmails, subject, notifTplCampaign, data) return app.sendNotification(cs.NotifyEmails, subject, notifTplCampaign, data)
} }
return manager.New(manager.Config{ return manager.New(manager.Config{
Concurrency: ko.Int("app.concurrency"), Concurrency: ko.Int("app.concurrency"),
MaxSendErrors: ko.Int("app.max_send_errors"), MaxSendErrors: ko.Int("app.max_send_errors"),
FromEmail: app.constants.FromEmail, FromEmail: cs.FromEmail,
UnsubURL: app.constants.UnsubURL, UnsubURL: cs.UnsubURL,
OptinURL: app.constants.OptinURL, OptinURL: cs.OptinURL,
LinkTrackURL: app.constants.LinkTrackURL, LinkTrackURL: cs.LinkTrackURL,
ViewTrackURL: app.constants.ViewTrackURL, ViewTrackURL: cs.ViewTrackURL,
}, newManagerDB(app.queries), campNotifCB, lo) }, newManagerDB(q), campNotifCB, lo)
} }
// initImporter initializes the bulk subscriber importer. // initImporter initializes the bulk subscriber importer.
func initImporter(app *App) *subimporter.Importer { func initImporter(q *Queries, db *sqlx.DB, app *App) *subimporter.Importer {
return subimporter.New(app.queries.UpsertSubscriber.Stmt, return subimporter.New(q.UpsertSubscriber.Stmt,
app.queries.UpsertBlacklistSubscriber.Stmt, q.UpsertBlacklistSubscriber.Stmt,
app.queries.UpdateListsDate.Stmt, q.UpdateListsDate.Stmt,
app.db.DB, db.DB,
func(subject string, data interface{}) error { func(subject string, data interface{}) error {
app.sendNotification(app.constants.NotifyEmails, subject, notifTplImport, data) app.sendNotification(app.constants.NotifyEmails, subject, notifTplImport, data)
return nil return nil

View file

@ -133,8 +133,8 @@ func main() {
log: lo, log: lo,
} }
_, app.queries = initQueries(queryFilePath, db, fs, true) _, app.queries = initQueries(queryFilePath, db, fs, true)
app.manager = initCampaignManager(app) app.manager = initCampaignManager(app.queries, app.constants, app)
app.importer = initImporter(app) app.importer = initImporter(app.queries, db, app)
app.messenger = initMessengers(app.manager) app.messenger = initMessengers(app.manager)
app.notifTpls = initNotifTemplates("/email-templates/*.html", fs, app.constants) app.notifTpls = initNotifTemplates("/email-templates/*.html", fs, app.constants)