webhooks_emitter v0.1.0 WebhooksEmitter View Source
Documentation for WebhooksEmitter
.
Link to this section Summary
Functions
Attaches a new emitter to the event.
Attaches a new emitter to a list of events.
Detaches an emitter.
Emits an event, invoking all emitters attached to it.
Link to this section Types
Link to this section Functions
attach(emitter_id, event_name, config)
View Sourceattach(emitter_id(), event_name(), WebhooksEmitter.Config.t()) :: :ok | {:error, :already_exists}
Attaches a new emitter to the event.
emitter_id must be unique, if another emitter with the same ID already exists {:error, :already_exists} is returned.
Each emitter is a separate process that performs HTTP operations, while keeping a queue of events in order to performs retries. So events handled by the same emitter are processed sequentially. This means also that if a request fails and more events are to be handled by the emitter, the events are queued until the current delivery succeed or fails because of hitting the maximum retries. At this point the event is lost forever.
If same url needs to process many events, attach_many/3
can be used.
attach_many(emitter_id, event_names, config)
View Sourceattach_many(emitter_id(), event_names(), WebhooksEmitter.Config.t()) :: :ok | {:error, :already_exists}
Attaches a new emitter to a list of events.
Accepts a list of event names. Apart from that, works like attach/3
.
Detaches an emitter.
Stops the process and removes it from the supervision tree, disregarding any queued message. Always returns :ok.
Emits an event, invoking all emitters attached to it.
Allows to set a request_id, that is inserted into the HTTP request as X-Webhooks-Delivery private header.
If the request id is not set, a new one is generated and returned as {:ok, UUID.uuid4()}
.
Otherwise just return the {:ok, request_id} tuple.
The map payload is parsed in order to be safe for json encoding, basically ensures that any key or value that cannot be directly converted to string is handled correctly by inspecting them.
So keys and values in the payload are converted like:
- values as tuples are transformed to list
- keys as tuples are transformed to list, then inspected to obtain a string
- keys as list are inspected to obtain a string
- refs are always inspected