You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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?
The text was updated successfully, but these errors were encountered:
jasonbarbee
changed the title
Event Handler trouble passing a custom
Event Handler trouble passing a custom event_handler
Jul 9, 2019
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?
The text was updated successfully, but these errors were encountered: