Skip to content

Commit 42448f5

Browse files
feat: multiple mailmen
1 parent 913bd59 commit 42448f5

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

cmd/smtpbridge/main.go

+5-3
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,11 @@ func run(flags *flag.FlagSet) lieut.Executor {
158158
return nil
159159
}))
160160

161-
// Mailman
162-
mailman := mailman.New(app, bus, fileStore, cfg.EndpointFactory)
163-
super.Add(mailman)
161+
for i := 1; i <= cfg.MailmanCount; i++ {
162+
// Mailman
163+
mailman := mailman.New(i, app, bus, fileStore, cfg.EndpointFactory)
164+
super.Add(mailman)
165+
}
164166

165167
// SMTP
166168
if !cfg.SMTPDisable {

config/config.go

+2
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ type Config struct {
4040
HealthcheckURL string
4141
HealthcheckInterval time.Duration
4242
HealthcheckStartup bool
43+
MailmanCount int
4344
HTTPDisable bool
4445
HTTPAddress string
4546
HTTPPort uint16
@@ -339,6 +340,7 @@ func (p Parser) Parse(raw Raw) (Config, error) {
339340
HealthcheckURL: raw.HealthcheckURL,
340341
HealthcheckInterval: healthcheckInterval,
341342
HealthcheckStartup: raw.HealthcheckStartup,
343+
MailmanCount: 1,
342344
Debug: raw.Debug,
343345
TimeHourFormat: timeHourFormat,
344346
DatabasePath: databasePath,

internal/mailman/mailman.go

+8-4
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,16 @@ import (
1313
)
1414

1515
type Mailman struct {
16+
id int
1617
bus core.Bus
1718
app core.App
1819
fileStore endpoint.FileStore
1920
endpointFactory endpoint.Factory
2021
}
2122

22-
func New(app core.App, bus core.Bus, fileStore endpoint.FileStore, endpointFactory endpoint.Factory) Mailman {
23+
func New(id int, app core.App, bus core.Bus, fileStore endpoint.FileStore, endpointFactory endpoint.Factory) Mailman {
2324
return Mailman{
25+
id: id,
2426
app: app,
2527
bus: bus,
2628
fileStore: fileStore,
@@ -46,7 +48,9 @@ func (m Mailman) Serve(ctx context.Context) error {
4648
return nil
4749
case <-checkC:
4850
for {
49-
tracer := m.app.Tracer(trace.SourceMailman)
51+
tracer := m.app.
52+
Tracer(trace.SourceMailman).
53+
Sticky(trace.WithKV("mailman", m.id))
5054

5155
maybeEnv, err := m.app.MailmanDequeue(ctx)
5256
if err != nil {
@@ -60,12 +64,12 @@ func (m Mailman) Serve(ctx context.Context) error {
6064

6165
tracer = tracer.Sticky(trace.WithEnvelope(env.Message.ID))
6266

63-
tracer.Trace(ctx, "mailman.start")
67+
tracer.Trace(ctx, "mailman.wake")
6468
if err := m.send(ctx, tracer, env); err != nil {
6569
tracer.Trace(ctx, "mailman.error", trace.WithError(err))
6670
log.Err(err).Int64("envelope-id", env.Message.ID).Msg("Failed to send envelope")
6771
}
68-
tracer.Trace(ctx, "mailman.end")
72+
tracer.Trace(ctx, "mailman.sleep")
6973
}
7074
}
7175
}

0 commit comments

Comments
 (0)