2022-01-01 13:13:43 -05:00
|
|
|
# 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-02-03 07:18:57 -05:00
|
|
|
@instance ||= Store.new { |store| configure!(store) }
|
2022-01-01 13:13:43 -05:00
|
|
|
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-02-03 07:18:57 -05:00
|
|
|
def self.configure!(store)
|
|
|
|
###
|
|
|
|
# Add subscriptions here:
|
2022-01-01 13:13:43 -05:00
|
|
|
|
2022-02-03 07:18:57 -05:00
|
|
|
store.subscribe ::MergeRequests::UpdateHeadPipelineWorker, to: ::Ci::PipelineCreatedEvent
|
2022-02-10 07:18:48 -05:00
|
|
|
store.subscribe ::Namespaces::UpdateRootStatisticsWorker, to: ::Projects::ProjectDeletedEvent
|
2022-07-06 11:08:08 -04:00
|
|
|
|
|
|
|
store.subscribe ::Pages::InvalidateDomainCacheWorker, to: ::Pages::PageDeployedEvent
|
|
|
|
store.subscribe ::Pages::InvalidateDomainCacheWorker, to: ::Pages::PageDeletedEvent
|
2022-07-08 14:10:05 -04:00
|
|
|
store.subscribe ::Pages::InvalidateDomainCacheWorker, to: ::Projects::ProjectDeletedEvent
|
2022-07-14 05:09:25 -04:00
|
|
|
store.subscribe ::Pages::InvalidateDomainCacheWorker, to: ::Projects::ProjectCreatedEvent
|
2022-07-20 17:10:19 -04:00
|
|
|
store.subscribe ::Pages::InvalidateDomainCacheWorker, to: ::Projects::ProjectPathChangedEvent
|
2022-08-03 05:12:13 -04:00
|
|
|
store.subscribe ::Pages::InvalidateDomainCacheWorker, to: ::Projects::ProjectArchivedEvent
|
2022-08-09 11:11:31 -04:00
|
|
|
store.subscribe ::Pages::InvalidateDomainCacheWorker, to: ::Projects::ProjectTransferedEvent
|
2022-10-11 08:09:17 -04:00
|
|
|
store.subscribe ::Pages::InvalidateDomainCacheWorker,
|
|
|
|
to: ::Projects::ProjectAttributesChangedEvent,
|
|
|
|
if: -> (event) { event.pages_related? }
|
2022-10-17 08:10:08 -04:00
|
|
|
store.subscribe ::Pages::InvalidateDomainCacheWorker,
|
|
|
|
to: ::Projects::ProjectFeaturesChangedEvent,
|
|
|
|
if: -> (event) { event.pages_related? }
|
2022-08-11 11:11:19 -04:00
|
|
|
store.subscribe ::Pages::InvalidateDomainCacheWorker, to: ::Groups::GroupTransferedEvent
|
2022-08-15 14:12:51 -04:00
|
|
|
store.subscribe ::Pages::InvalidateDomainCacheWorker, to: ::Groups::GroupPathChangedEvent
|
2022-08-16 14:12:52 -04:00
|
|
|
store.subscribe ::Pages::InvalidateDomainCacheWorker, to: ::Groups::GroupDeletedEvent
|
2022-09-29 11:09:34 -04:00
|
|
|
store.subscribe ::Pages::InvalidateDomainCacheWorker, to: ::PagesDomains::PagesDomainDeletedEvent
|
2022-10-03 08:08:27 -04:00
|
|
|
store.subscribe ::Pages::InvalidateDomainCacheWorker, to: ::PagesDomains::PagesDomainUpdatedEvent
|
2022-10-04 14:08:15 -04:00
|
|
|
store.subscribe ::Pages::InvalidateDomainCacheWorker, to: ::PagesDomains::PagesDomainCreatedEvent
|
2022-08-03 05:12:13 -04:00
|
|
|
|
2022-08-01 17:09:22 -04:00
|
|
|
store.subscribe ::MergeRequests::CreateApprovalEventWorker, to: ::MergeRequests::ApprovedEvent
|
2022-08-10 05:11:40 -04:00
|
|
|
store.subscribe ::MergeRequests::CreateApprovalNoteWorker, to: ::MergeRequests::ApprovedEvent
|
|
|
|
store.subscribe ::MergeRequests::ResolveTodosAfterApprovalWorker, to: ::MergeRequests::ApprovedEvent
|
|
|
|
store.subscribe ::MergeRequests::ExecuteApprovalHooksWorker, to: ::MergeRequests::ApprovedEvent
|
2022-01-01 13:13:43 -05:00
|
|
|
end
|
|
|
|
private_class_method :configure!
|
|
|
|
end
|
|
|
|
end
|
2022-02-03 07:18:57 -05:00
|
|
|
|
|
|
|
Gitlab::EventStore.prepend_mod_with('Gitlab::EventStore')
|