Skip to content

Hyrax's Event Bus (Hyrax::Publisher)

tamsin johnson edited this page Dec 10, 2020 · 14 revisions

Beginning in 3.0.0, Hyrax supports a topic-based event bus using dry-events. This interface seeks to provide a single system for supporting event-driven behavior in Hyrax and dependent applications.

Whenever Hyrax performs one of the actions associated with a named event, it promises to push an event to the Publisher with a payload. The event payloads are specific to each event type/topic, but usually contain the object acted on and the user responsible for triggering the event. Applications can subscribe Listeners which will be triggered and passed the event and payload whenever an event is published. Likewise, applications can (and should) publish events to trigger Hyrax's listeners.

The key point of reference for the implementation of this system is Hyrax::Publisher.

Topics

'batch.created'
'file.set.audited'
'file.set.attached'
'file.set.url.imported'
'file.set.restored'
'object.deleted'
'object.failed_deposit'
'object.deposited'
'object.acl.updated'
'object.metadata.updated'

Replacing Hyrax::Callbacks

Hyrax had a prior interface offering pub/sub-like behavior: Hyrax::Callbacks. This system allowed a user to set a block as a named callback method, which would then be triggered by engine or application code.

# to register
Hyrax.config.callback.set(:after_create_concern) do |curation_concern, user|
  ContentDepositEventJob.perform_later(curation_concern, user)
end

# from application code
Hyrax.config.callback.run(:after_create_concern, curation_concern, user)

In 3.0.0, this interface is replaced by Hyrax::Publisher. The old default callbacks are deprecated for removal in 4.0.0, and their implementations have been ported to Listener classes. The callbacks themselves now publish events (see chart below) which triggers the ported code by default. Existing Hyrax engine code that invokes Hyrax.config.callback will continue to do until 4.0.0 but, in general, new code won't invoke callbacks. If your application disabled default callbacks, registered/enabled custom ones, or overwrote callback behavior, this should provide you a measure of compatibility.

We recommend updating existing Hyrax::Callbacks usage soon. Hyrax plans to make extensive internal usage of Hyrax::Publisher during the 3.0.0 release series and beyond.

Callback Event(s)
:after_create_concern 'object.deposited', 'object.metadata.updated'
:after_create_fileset 'file_set.attached'
:after_revert_content 'file_set.restored'
:after_update_metadata 'object.metadata.updated'
:after_destroy 'object.deleted'
:after_batch_create_success 'batch.created' (result: :success)
:after_batch_create_failure 'batch.created' (result: :failure)
:after_import_url_failure 'file.set.url.imported' (result: :failure)
Clone this wiki locally