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
func RandBool() bool {
return rand.Intn(2) == 0
return rand.Uint64()&1 == 1
}
// FakeEmail generates a fake email address

35
main.go
View File

@@ -179,6 +179,7 @@ func main() {
if !cached {
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")
entries <- fullEntry.Email
}
@@ -186,23 +187,35 @@ func main() {
var wg sync.WaitGroup
// Process each email
for email := range entries {
log.Info().Str("email", email).Msg("Unsubscribing Email")
QueueEmail := func(email string, fake bool) {
wg.Add(1)
go func(email string) {
defer wg.Done()
Unsubscribe(email)
_, err := Unsubscribe(email)
if err != nil {
log.Err(err).Str("email", email).Msg("Error occurred while trying to unsubscribe email")
}
log.Info().Str("email", email).Msg(lo.Ternary(!fake, "Email Unsubscribed", "Fake Email Unsubscribed"))
wg.Done()
}(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() {
log.Info().Str("email", email).Msg("Unsubscribing Fake Email")
wg.Add(1)
go func(email string) {
defer wg.Done()
go Unsubscribe(FakeEmail())
}(email)
QueueEmail(FakeEmail(), true)
}
}
}