feat(mail): send service identity mail through a leased worker
This commit is contained in:
1 parent
204c6bae62
commit
d21fd49a42
58 files changed
+7577
-164
No files matched your search
@@ -20,6 +20,7 @@ import (
|
||||
"lincodex/backend/internal/port/outbound"
|
||||
"lincodex/backend/internal/worker/deliverymetrics"
|
||||
"lincodex/backend/internal/worker/jobrunner"
|
||||
"lincodex/backend/internal/worker/mailsender"
|
||||
"lincodex/backend/internal/worker/outboxrelay"
|
||||
)
|
||||
|
||||
@@ -33,8 +34,8 @@ type Application struct {
|
||||
apiHandler http.Handler
|
||||
metrics *prometheus.Metrics
|
||||
logger *slog.Logger
|
||||
// mailSender is the transport selected by EMAIL_PROVIDER. No usecase
|
||||
// sends mail yet; the delivery layer will take it from here.
|
||||
// mailSender is the transport selected by EMAIL_PROVIDER. Only the mail
|
||||
// sending worker calls it.
|
||||
mailSender outbound.MailSender
|
||||
// relay publishes outbox events while the servers run. It is nil when
|
||||
// the relay is disabled or the database is not configured.
|
||||
@@ -46,6 +47,10 @@ type Application struct {
|
||||
// is nil when the worker is disabled, no job kind is registered, or the
|
||||
// database is not configured.
|
||||
jobs *jobrunner.Worker
|
||||
// mailSending sends the stored service mail of the account flows while
|
||||
// the servers run. It is nil with EMAIL_PROVIDER=disabled or when the
|
||||
// database is not configured.
|
||||
mailSending *mailsender.Worker
|
||||
// deliveryMetrics reads the delivery and quota gauges while the servers
|
||||
// run. It is nil when the database is not configured.
|
||||
deliveryMetrics *deliverymetrics.Sampler
|
||||
@@ -60,6 +65,7 @@ func NewApplication(
|
||||
relay *outboxrelay.Relay,
|
||||
consumers eventConsumers,
|
||||
jobs *jobrunner.Worker,
|
||||
mailSending *mailsender.Worker,
|
||||
deliveryMetrics *deliverymetrics.Sampler,
|
||||
) *Application {
|
||||
return &Application{
|
||||
@@ -71,6 +77,7 @@ func NewApplication(
|
||||
relay: relay,
|
||||
consumers: consumers,
|
||||
jobs: jobs,
|
||||
mailSending: mailSending,
|
||||
deliveryMetrics: deliveryMetrics,
|
||||
}
|
||||
}
|
||||
@@ -189,16 +196,18 @@ func (application *Application) run(ctx context.Context) error {
|
||||
stopRun()
|
||||
// The relay finishes its pass in progress within SHUTDOWN_TIMEOUT, each
|
||||
// consumer its record in progress within CONSUMER_SHUTDOWN_GRACE plus
|
||||
// one offset commit, and the job worker its job in progress within
|
||||
// JOBS_SHUTDOWN_GRACE plus one release, so the cleanup that closes their
|
||||
// pools, producer, and group members runs after all of them stopped.
|
||||
// one offset commit, the job worker its job in progress within
|
||||
// JOBS_SHUTDOWN_GRACE plus one release, and the mail sending worker its
|
||||
// send in progress within its shutdown grace plus one settlement, so the
|
||||
// cleanup that closes their pools, producer, and group members runs after
|
||||
// all of them stopped.
|
||||
<-workersStopped
|
||||
application.logger.Info("workers stopped")
|
||||
return err
|
||||
}
|
||||
|
||||
// startWorkers runs the relay, every consumer, the scheduled job worker, and
|
||||
// the delivery metrics sampler until ctx ends and returns a channel that
|
||||
// startWorkers runs the relay, every consumer, the scheduled job worker, the
|
||||
// mail sending worker, and the delivery metrics sampler until ctx ends and returns a channel that
|
||||
// closes when all of them have stopped. The workers stop together with the
|
||||
// servers; none of them depends on another.
|
||||
func (application *Application) startWorkers(ctx context.Context) <-chan struct{} {
|
||||
@@ -212,6 +221,9 @@ func (application *Application) startWorkers(ctx context.Context) <-chan struct{
|
||||
if application.jobs != nil {
|
||||
workers.Go(func() { application.jobs.Run(ctx) })
|
||||
}
|
||||
if application.mailSending != nil {
|
||||
workers.Go(func() { application.mailSending.Run(ctx) })
|
||||
}
|
||||
if application.deliveryMetrics != nil {
|
||||
workers.Go(func() { application.deliveryMetrics.Run(ctx) })
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user