Class: Hecks::Runtime::Event

Inherits:
Struct
  • Object
show all
Defined in:
lib/hecks/runtime/event.rb

Overview

correlation is NOT on the wire — to_h below deliberately omits it, the same as bin/run's own event projection does. It is runtime bookkeeping stamped by Dispatcher#dispatch when a saga leg's own dispatch causes this event (see SagaInterpreter#deliver_saga_dispatch and #saga_correlation) : a Hash of correlation_head -> correlation value, so an event caused by one saga cannot be misread by an unrelated one correlating on a different field. Absent for any event no saga dispatch caused, which is most of them.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#aggregateObject

Returns the value of attribute aggregate

Returns:

  • (Object)

    the current value of aggregate



13
14
15
# File 'lib/hecks/runtime/event.rb', line 13

def aggregate
  @aggregate
end

#correlationObject

Returns the value of attribute correlation

Returns:

  • (Object)

    the current value of correlation



13
14
15
# File 'lib/hecks/runtime/event.rb', line 13

def correlation
  @correlation
end

#idObject

Returns the value of attribute id

Returns:

  • (Object)

    the current value of id



13
14
15
# File 'lib/hecks/runtime/event.rb', line 13

def id
  @id
end

#nameObject

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



13
14
15
# File 'lib/hecks/runtime/event.rb', line 13

def name
  @name
end

#occurred_atObject

Returns the value of attribute occurred_at

Returns:

  • (Object)

    the current value of occurred_at



13
14
15
# File 'lib/hecks/runtime/event.rb', line 13

def occurred_at
  @occurred_at
end

#payloadObject

Returns the value of attribute payload

Returns:

  • (Object)

    the current value of payload



13
14
15
# File 'lib/hecks/runtime/event.rb', line 13

def payload
  @payload
end

Instance Method Details

#emit!Object

AN EMITTED EVENT IS A RECORD OF SOMETHING THAT HAPPENED, and a mutable audit trail is not one. The PAYLOAD — the domain fact the event carries — is frozen THROUGH on emission: freezing the Hash alone would leave every value in it editable in place, which is the shape all four previous freezing bugs had.

THE WHOLE EVENT, not just its payload. Correlation used to be merged onto already-emitted events by Dispatcher#dispatch, which is what kept an event writable after it had happened; it is set at construction now, because it is part of the transaction and known from dispatch's own argument before anything is emitted.

The LOG stays appendable: new events are still recorded. It is each event that stops changing once it exists.



28
29
30
31
32
# File 'lib/hecks/runtime/event.rb', line 28

def emit!
  Freezer.deep(payload)
  Freezer.deep(correlation)
  freeze
end

#inspectObject



48
# File 'lib/hecks/runtime/event.rb', line 48

def inspect = "#<Event #{self}>"

#to_hObject



34
35
36
37
38
39
40
41
42
# File 'lib/hecks/runtime/event.rb', line 34

def to_h
  {
    name:        name,
    aggregate:   aggregate,
    id:          id,
    payload:     payload,
    occurred_at: occurred_at
  }
end

#to_sObject



44
45
46
# File 'lib/hecks/runtime/event.rb', line 44

def to_s
  "#{name}(#{aggregate}##{id}) #{payload.inspect}"
end