Skip to content

Mark emails as unreachable #393

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

Merged
merged 3 commits into from
Apr 6, 2025

Conversation

henriqueberlesi
Copy link
Contributor

My attempt on #390.

Updating the handle_result from Keila.Mailings.Worker to deal with the already existent :invalid_email return error. The action will update the failed_at date for the recipient, and update the recipient's contact to the unreachable atom.

Also, refactored a few queries into their own private functions. Maybe in the future these functions could be moved to their own service/module?

Also, @wmnnd: I have not found any tests covering this file. Should we add tests with this PR?

Thanks!

@wmnnd
Copy link
Contributor

wmnnd commented Mar 9, 2025

Hey @henriqueberlesi, thanks you for taking on this issue! I’ll take a closer look in the coming days 😊

@@ -106,19 +107,70 @@ defmodule Keila.Mailings.Worker do
# Email was already sent
defp handle_result({:error, :already_sent}, _), do: {:cancel, :already_sent}

# Email is invalid
defp handle_result({:error, :invalid_email}, recipient) do
Multi.new()
Copy link
Contributor

@wmnnd wmnnd Mar 28, 2025

Choose a reason for hiding this comment

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

Could you refactor this to just

Repo.transaction(fn ->
  recipient
  |> set_recipient_failed_query()
  |> Repo.update_all([])

  # ...
end)

We don’t really use Ecto.Multi anywhere else in the codebase and so I think overall this is easier to read 😊

@wmnnd
Copy link
Contributor

wmnnd commented Mar 28, 2025

Sorry it took so long, but overall this PR is looking good and is a valuable contribution, thank you! I just left one small comment – and once that’s been addressed, I’d be happy to merge 🚀

@henriqueberlesi
Copy link
Contributor Author

@wmnnd thanks for the feedback! I refactored Ecto.Multi out, as requested. Please let me know if there are any other changes needed.

@wmnnd wmnnd merged commit 9c06907 into pentacent:main Apr 6, 2025
2 checks passed
@wmnnd
Copy link
Contributor

wmnnd commented Apr 6, 2025

Excellent, thank you! Sorry for the nit-pick about Ecto.Multi 😅

@henriqueberlesi henriqueberlesi deleted the mark-emails-as-unreachable branch April 6, 2025 20:50
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.

2 participants