Skip to content

Commit 3f20664

Browse files
committed
make it run parallel
1 parent f00caa8 commit 3f20664

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

example-mail/mailer.go

+3-5
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,6 @@ curl -k -X POST -H "Authorization: Bearer ${TOKEN}" -H "Content-Type: applicatio
2424
2525
*/
2626

27-
const (
28-
emailParallel = 1
29-
)
30-
3127
var (
3228
opts *Opts
3329
jwtKey []byte
@@ -48,6 +44,7 @@ type Opts struct {
4844
SmtpPassword string
4945
SmtpHost string
5046
SmtpPort int
47+
Parallel int
5148
}
5249

5350
type EmailRequest struct {
@@ -171,6 +168,7 @@ func NewOpts() *Opts {
171168
flag.StringVar(&opts.SmtpPassword, "smtp-pw", lookupEnv("SMTP-PW"), "Password for the mail server")
172169
flag.IntVar(&opts.SmtpPort, "smtp-port", lookupEnvInt("SMTP-PORT", 587), "Port of the mailserver")
173170
flag.StringVar(&opts.SmtpHost, "smtp-host", lookupEnv("SMTP-HOST"), "Host of the mailserver")
171+
flag.IntVar(&opts.Parallel, "parallel", lookupEnvInt("PARALLEL", 4), "How many email should be send in parallel")
174172
flag.Usage = func() {
175173
fmt.Fprintf(flag.CommandLine.Output(), "Usage of %s:\n", os.Args[0])
176174
flag.PrintDefaults()
@@ -200,7 +198,7 @@ func main() {
200198

201199
//create a queue, and send one after the other
202200
queue = make(chan *EmailRequest)
203-
for i := 0; i < emailParallel; i++ {
201+
for i := 0; i < opts.Parallel; i++ {
204202
go func() {
205203
for {
206204
select {

0 commit comments

Comments
 (0)