I have a genserver that is taking messages from a websocket and passing them to an event handler. The event handler receives a map from the genserver and takes action where appropriate. So for example, in response to a new user create event, the event handler would check if the user's email address comes from a suspicious domain, and if so, take some actions to reduce abuse.
So in event_handler.ex
you can see that when a new message comes in for a user create event, I pass the message
to UserHandler.handle_suspicious_domain
. That function returns the same map which I pass to UserHandler.handle_suspicious_ip
. But
I'm not sure if that's idomatic since I'm not transforming the map, I'm just passing it from function to function.
Then you can see in user_handler.ex
that I take the domain name through a set of transformations and then make a decision.
Looking at line 25 you can see that I have a function that does nothing and only exists to prevent a crash. That seems wasteful and
also runs contrary to let it crash.
Any ideas on how to make this more idiomatic?
It might be better in EventHandler
to spawn a task for each of those steps steps(handle_suspicious_domain
and handle_suspicious_ip
) and then the task can crash if any part of the function doesn’t go exactly right. Does that seem like a better approach?