Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handlers/email: Ability to toggle sending emails or not #26

Merged
merged 4 commits into from
Jun 28, 2018

Conversation

Chiiruno
Copy link
Contributor

@Chiiruno Chiiruno commented Jun 2, 2018

Fixes #25
I also took care of a few possible data race hot spots if you don't mind.

@Chiiruno
Copy link
Contributor Author

Chiiruno commented Jun 15, 2018

@joeybloggs Hey sorry to ping you, any chance this could be merged?
Does it need anything?

@@ -119,6 +130,14 @@ func (email *Email) SetEmailConfig(host string, port int, username string, passw
email.formatter = email.formatFunc(email)
}

// SetSend enables or disables the email handler sending emails
func (email *Email) SetSend(send bool) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a more precise name might be better like SetEnabled

@@ -146,6 +165,9 @@ func defaultFormatFunc(email *Email) Formatter {

// Log handles the log entry
func (email *Email) Log(e log.Entry) {
if !email.send {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a race here, this needs to be surrounded by email.rw.Rlock() or changed to us atomic, which in this case might make more sense.

@@ -104,6 +104,7 @@ func TestEmailHandler(t *testing.T) {
email.SetTimestampFormat("MST")
email.SetTemplate(defaultTemplate)
email.SetEmailConfig("localhost", 3041, "", "", "from@email.com", []string{"to@email.com"})
email.SetSend(true)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be great if you could add an email test where it is set to false to ensure that when disabled it works appropriately.

@deankarn
Copy link
Contributor

@Chiiruno so sorry about that, slipped through the cracks

I've reviewed and a few minor things I think need to be addressed before it can be merged.

@Chiiruno
Copy link
Contributor Author

Chiiruno commented Jun 15, 2018

@joeybloggs Atomics ended up being a mess, so I decided to just go with the mutex, since it's a lot less lines and abstraction.
I can't figure out how to make a test for checking whether the email sends or not, if you know a way I'll implement it, I've been looking at this thing for an hour now.

@Chiiruno
Copy link
Contributor Author

For what it's worth, I tested this with my own email and it sends when it's enabled, doesn't when it's not.

@Chiiruno
Copy link
Contributor Author

@joeybloggs I'm not rushing you or anything, there's no real deadline I'm on, but here's a ping in case you forgot.

email.rw.RLock()

if !email.enabled {
return
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the Rlock will never be released here, I would also not have 2 lock and unlocks so close to each other, one here and another shortly below, I recommend expanding the scope to only lock/unlock once.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh wow, I can't believe I didn't notice that haha.

@deankarn
Copy link
Contributor

Hey @Chiiruno not rushing me, I reviewed and apparently forgot to hit submit, I thought I was waiting on you lolz

@Chiiruno
Copy link
Contributor Author

Chiiruno commented Jun 26, 2018

@joeybloggs Okay, that should be a bit more proper, what a silly mistake I made.
I'm not entirely sure this is how things work with Go, but I moved the var declarations below the mutex block to avoid having to wait on the mutex to malloc for multiple threads. (If already past the part where the mutex needs to cover)

@deankarn
Copy link
Contributor

@Chiiruno only one more thing, can a test be added that hits the not enabled logic.

then I can merge.

@Chiiruno
Copy link
Contributor Author

@joeybloggs I can't figure out any way to do this without adding extra variables and frankly, bloat.
I hate to ask, but could you write the test? I just can't figure out a sane way to do it.

@Chiiruno
Copy link
Contributor Author

I don't think I have a secure way of checking if once has already been done either.

@Chiiruno
Copy link
Contributor Author

Chiiruno commented Jun 27, 2018

Okay, so the test is part of the email package, so I actually have access to the struct.
I hope that's the test that you wanted.

@deankarn
Copy link
Contributor

@Chiiruno Thanks, I will merge tomorrow, I have no time today unfortunately

@deankarn deankarn merged commit 998a083 into go-playground:master Jun 28, 2018
@Chiiruno Chiiruno deleted the dev/email-handler branch June 28, 2018 23:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants