HackerExperience / Helix

GNU Affero General Public License v3.0
53 stars 10 forks source link

Relay `process_id` on side-effects performed after ProcessConclusionEvent #311

Closed renatomassaro closed 6 years ago

renatomassaro commented 6 years ago

FileDownload[Failed], FileUpload[Failed], ServerPasswordAcquired, Bruteforce[Failed]

This is quite common so check if it's possible to make it abstract/generic somehow.

renatomassaro commented 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.

renatomassaro commented 6 years ago

@kress95 how would that work out for you?

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.

renatomassaro commented 6 years ago

And I just realized the process_hash can be the process_id itself :joy: