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

Event Handler trouble passing a custom event_handler #2

Closed
jasonbarbee opened this issue Jul 9, 2019 · 3 comments
Closed

Event Handler trouble passing a custom event_handler #2

jasonbarbee opened this issue Jul 9, 2019 · 3 comments

Comments

@jasonbarbee
Copy link
Contributor

in my config.exs file I spent a while trying to get a custom handler to work here.
event_handler: fn(event) -> IO.puts("Event: #{inspect event} ") end
I changed it to
event_handler: Myapp.Sftp.Events
and
event_handler: Myapp.Sftp.Events.parse
and
event_handler: fn(event) -> Myapp.Sftp.Events.on_event(event) end
(I was surprised the function to function did not work, but I could not get it to work.)

but your code in sftp_file_handler.ex will not execute the varieties I listed, because I cannot pass a function to the config item. If I pass a function, it assumes /0 arrity, and fails to compile as a match.
Line in question-
handler -> handler.({event_name, state[:user], meta})

I modified my local copy like below, you pass a Module, with an Atom of the function.
in config.exs
event_handler: {Myapp.Sftp.Events, :on_event}

in sftp_file_handler.ex
Then you can apply the function like this in the case match above
{handler, function} -> apply(handler, function, [{event_name, state[:user], meta}])
Now, it calls Myapp.Sftp.Events.on_event(event), and is completely user configurable, and easy to read.

I can generate a pull request if you want, or is there some other way this is supposed to work?

@jasonbarbee jasonbarbee changed the title Event Handler trouble passing a custom Event Handler trouble passing a custom event_handler Jul 9, 2019
@jalpedersen
Copy link
Collaborator

This seems reasonable. Please send a pull request and I will merge it.

@jalpedersen
Copy link
Collaborator

And as a general rule, pull requests are very welcomed :-)

@jalpedersen
Copy link
Collaborator

I've just made the change myself as I as was doing some other changes as well. But feel free to send pull requests in future.

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

No branches or pull requests

2 participants