Closed renatomassaro closed 6 years ago
The "abstract" implementation is quite cool:
Here's the "as-transparent-as-it-can-be" interface:
event = generate_process_hash(event) # On TOP completion
process_completed_event = ProcessCompletedEvent.new(...., event) # Includes the has on ProcessCompletedEvent
### On the handler ###
def handle(event) do
if sucess do
Event.emit(my_successful_event, from: event)
else
Event.emit(my_bad_bad_event, from: event)
end
end
### On Helix.Event.emit/2 ###
def emit(event, from: prev_event) do
get_hash(prev_event) |> put_hash(event) |> emit()
end
There's another benefit to this: since the Event emission API is generic (it's not specific to process hash), we may extend this behavior later on, like generating a linked graph from all events being emitted, or pass on an request/event identifier, etc.
@kress95 how would that work out for you?
event_id
is handledevent.__meta__.process_hash
Possible gotcha: There may have some events containing the process_hash that you, as a client, is not interested at all. I guess you would simply have to ignore this, so not a problem.
And I just realized the process_hash
can be the process_id
itself :joy:
FileDownload[Failed], FileUpload[Failed], ServerPasswordAcquired, Bruteforce[Failed]
This is quite common so check if it's possible to make it abstract/generic somehow.