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. The key point of reference for the implementation of this system is Hyrax::Publisher.

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