Latest iteration on email processing, RandBool perf

This commit is contained in:
2023-12-30 17:14:06 -06:00
parent 1a00f791fa
commit ba8eadf1d9
2 changed files with 28 additions and 15 deletions

View File

@@ -193,7 +193,7 @@ func Bytes(bytes uint64) string {
// RandBool returns a random boolean // RandBool returns a random boolean
func RandBool() bool { func RandBool() bool {
return rand.Intn(2) == 0 return rand.Uint64()&1 == 1
} }
// FakeEmail generates a fake email address // FakeEmail generates a fake email address

41
main.go
View File

@@ -179,6 +179,7 @@ func main() {
if !cached { if !cached {
log.Info().Str("name", fullEntry.Name).Str("email", fullEntry.Email).Msg("New Email Found") log.Info().Str("name", fullEntry.Name).Str("email", fullEntry.Email).Msg("New Email Found")
} }
log.Debug().Str("name", fullEntry.Name).Str("email", fullEntry.Email).Msg("Entry Processed") log.Debug().Str("name", fullEntry.Name).Str("email", fullEntry.Email).Msg("Entry Processed")
entries <- fullEntry.Email entries <- fullEntry.Email
} }
@@ -186,23 +187,35 @@ func main() {
var wg sync.WaitGroup var wg sync.WaitGroup
// Process each email QueueEmail := func(email string, fake bool) {
for email := range entries {
log.Info().Str("email", email).Msg("Unsubscribing Email")
wg.Add(1) wg.Add(1)
go func(email string) { go func(email string) {
defer wg.Done() _, err := Unsubscribe(email)
Unsubscribe(email) if err != nil {
}(email) log.Err(err).Str("email", email).Msg("Error occurred while trying to unsubscribe email")
}
// 1/2 chance to unsubscribe fake email log.Info().Str("email", email).Msg(lo.Ternary(!fake, "Email Unsubscribed", "Fake Email Unsubscribed"))
if RandBool() {
log.Info().Str("email", email).Msg("Unsubscribing Fake Email") wg.Done()
wg.Add(1)
go func(email string) { }(email)
defer wg.Done() }
go Unsubscribe(FakeEmail())
}(email) // Process each email
for email := range entries {
seen, err := CheckEmail(email)
if err != nil {
log.Err(err).Str("email", email).Msg("Unable to Check Email Unsubscription State")
}
if !seen {
QueueEmail(email, false)
// 1/2 chance to unsubscribe fake email
if RandBool() {
QueueEmail(FakeEmail(), true)
}
} }
} }