Sha256: 2568526bf33c703d0f3dc5006c2225e9b86245113b26a5170d8f044ae7edc3be

Contents?: true

Size: 1.61 KB

Versions: 1

Compression:

Stored size: 1.61 KB

Contents

# frozen_string_literal: true

require_relative 'events/publisher'

module Esse
  # Extension used for classes that can pub/sub events
  #
  # Examples:
  #
  #   # Publish an event
  #   Esse::Events.publish('elasticsearch.create_index', { definition: {index_name: 'my_index'} })
  #   # Subscribe to an event
  #   Esse::Events.subscribe('elasticsearch.create_index') do |event|
  #     puts event.payload
  #   end
  #
  #   # Publish an event using instrumentation
  #   Esse::Events.instrument('elasticsearch.create_index') do |payload|
  #     payload[:definition] = {index_name: 'my_index'}
  #     # Some slow action
  #   end
  #   Esse::Events.subscribe('elasticsearch.create_index') do |event|
  #     puts event.payload[:runtime] # Extra information about the amount of time the action took
  #   end
  #
  #   # Attach a listener to the event bus
  #   class MyEventListener
  #     def on_elasticsearch_create_index(event)
  #       puts event.payload
  #     end
  #   end
  #   listener = MyEventListener.new
  #   Esse::Events.attach(listener)
  #   # Dettash the listener
  #   Esse::Events.detach(listener)
  #
  #
  module Events
    include Publisher

    register_event 'elasticsearch.close'
    register_event 'elasticsearch.open'
    register_event 'elasticsearch.create_index'
    register_event 'elasticsearch.delete_index'
    register_event 'elasticsearch.update_mapping'
    register_event 'elasticsearch.update_settings'
    register_event 'elasticsearch.update_aliases'
    register_event 'elasticsearch.bulk'
    register_event 'elasticsearch.search'
    register_event 'elasticsearch.execute_search_query'
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
esse-0.2.2 lib/esse/events.rb