2022-03-02 08:16:31 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
# Gitlab::EventStore is a simple pub-sub mechanism that lets you publish
|
|
|
|
# domain events and use Sidekiq workers as event handlers.
|
|
|
|
#
|
|
|
|
# It can be used to decouple domains from different bounded contexts
|
|
|
|
# by publishing domain events and let any interested parties subscribe
|
|
|
|
# to them.
|
|
|
|
#
|
|
|
|
module Gitlab
|
|
|
|
module EventStore
|
|
|
|
Error = Class.new(StandardError)
|
|
|
|
InvalidEvent = Class.new(Error)
|
|
|
|
InvalidSubscriber = Class.new(Error)
|
|
|
|
|
|
|
|
def self.publish(event)
|
|
|
|
instance.publish(event)
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.instance
|
2022-04-04 11:22:00 +05:30
|
|
|
@instance ||= Store.new { |store| configure!(store) }
|
2022-03-02 08:16:31 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
# Define all event subscriptions using:
|
|
|
|
#
|
|
|
|
# store.subscribe(DomainA::SomeWorker, to: DomainB::SomeEvent)
|
|
|
|
#
|
|
|
|
# It is possible to subscribe to a subset of events matching a condition:
|
|
|
|
#
|
|
|
|
# store.subscribe(DomainA::SomeWorker, to: DomainB::SomeEvent), if: ->(event) { event.data == :some_value }
|
|
|
|
#
|
2022-04-04 11:22:00 +05:30
|
|
|
def self.configure!(store)
|
|
|
|
###
|
|
|
|
# Add subscriptions here:
|
2022-03-02 08:16:31 +05:30
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
store.subscribe ::MergeRequests::UpdateHeadPipelineWorker, to: ::Ci::PipelineCreatedEvent
|
|
|
|
store.subscribe ::Namespaces::UpdateRootStatisticsWorker, to: ::Projects::ProjectDeletedEvent
|
2022-08-13 15:12:31 +05:30
|
|
|
|
|
|
|
store.subscribe ::Pages::InvalidateDomainCacheWorker, to: ::Pages::PageDeployedEvent
|
|
|
|
store.subscribe ::Pages::InvalidateDomainCacheWorker, to: ::Pages::PageDeletedEvent
|
|
|
|
store.subscribe ::Pages::InvalidateDomainCacheWorker, to: ::Projects::ProjectDeletedEvent
|
|
|
|
store.subscribe ::Pages::InvalidateDomainCacheWorker, to: ::Projects::ProjectCreatedEvent
|
2022-08-27 11:52:29 +05:30
|
|
|
store.subscribe ::Pages::InvalidateDomainCacheWorker, to: ::Projects::ProjectPathChangedEvent
|
|
|
|
store.subscribe ::Pages::InvalidateDomainCacheWorker, to: ::Projects::ProjectArchivedEvent
|
|
|
|
store.subscribe ::Pages::InvalidateDomainCacheWorker, to: ::Projects::ProjectTransferedEvent
|
|
|
|
store.subscribe ::Pages::InvalidateDomainCacheWorker, to: ::Groups::GroupTransferedEvent
|
|
|
|
store.subscribe ::Pages::InvalidateDomainCacheWorker, to: ::Groups::GroupPathChangedEvent
|
|
|
|
store.subscribe ::Pages::InvalidateDomainCacheWorker, to: ::Groups::GroupDeletedEvent
|
|
|
|
|
|
|
|
store.subscribe ::MergeRequests::CreateApprovalEventWorker, to: ::MergeRequests::ApprovedEvent
|
|
|
|
store.subscribe ::MergeRequests::CreateApprovalNoteWorker, to: ::MergeRequests::ApprovedEvent
|
|
|
|
store.subscribe ::MergeRequests::ResolveTodosAfterApprovalWorker, to: ::MergeRequests::ApprovedEvent
|
|
|
|
store.subscribe ::MergeRequests::ExecuteApprovalHooksWorker, to: ::MergeRequests::ApprovedEvent
|
2022-03-02 08:16:31 +05:30
|
|
|
end
|
|
|
|
private_class_method :configure!
|
|
|
|
end
|
|
|
|
end
|
2022-04-04 11:22:00 +05:30
|
|
|
|
|
|
|
Gitlab::EventStore.prepend_mod_with('Gitlab::EventStore')
|