-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
eventsimple outbox processor is instantiated once
- Loading branch information
Showing
17 changed files
with
154 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# frozen_string_literal: true | ||
|
||
module Eventsimple | ||
VERSION = '1.3.3' | ||
VERSION = '1.4.0' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
require 'eventsimple/outbox/consumer' | ||
|
||
module UserComponent | ||
class Consumer | ||
extend Eventsimple::Outbox::Consumer | ||
|
||
consumes_event UserEvent | ||
processor EventProcessor | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module UserComponent | ||
class EventProcessor | ||
def call(event) | ||
# no-op | ||
end | ||
end | ||
end |
13 changes: 13 additions & 0 deletions
13
spec/dummy/db/migrate/20240419175459_create_eventsimple_outbox_cursor.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# frozen_string_literal: true | ||
|
||
class CreateEventsimpleOutboxCursor < ActiveRecord::Migration[7.1] | ||
def change | ||
create_table :eventsimple_outbox_cursors do |t| | ||
t.string :event_klass, null: false | ||
t.integer :group_number, null: false | ||
t.bigint :cursor, null: false | ||
|
||
t.index [:event_klass, :group_number], unique: true | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
spec/dummy/spec/components/user_component/consumer_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
RSpec.describe UserComponent::Consumer do | ||
let(:mock_processor) { instance_double(UserComponent::EventProcessor, :call) } | ||
|
||
before do | ||
described_class._processor = mock_processor | ||
allow(mock_processor).to receive(:call) | ||
end | ||
|
||
it 'consumes events' do | ||
expect(described_class._event_klass).to eq(UserEvent) | ||
end | ||
|
||
it 'has a processor' do | ||
expect(described_class._processor_klass).to eq(UserComponent::EventProcessor) | ||
end | ||
|
||
describe '.run_consumer' do | ||
before do | ||
UserComponent::Events::Created.create!( | ||
user: User.new, | ||
data: { | ||
canonical_id: SecureRandom.uuid, | ||
username: 'test-user', | ||
email: '[email protected]', | ||
}, | ||
) | ||
end | ||
|
||
it 'records the last processed event position' do | ||
cursor = Eventsimple::Outbox::Cursor.fetch(UserEvent, group_number: 0) | ||
expect(cursor).to be(0) | ||
|
||
described_class.run_consumer(group_number: 0, stop_at_end: true) | ||
|
||
expect(mock_processor).to have_received(:call).once | ||
|
||
cursor = Eventsimple::Outbox::Cursor.fetch(UserEvent, group_number: 0) | ||
expect(cursor).to eq(UserEvent.last.id) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# frozen_string_literal: true | ||
|
||
FactoryBot.define do | ||
factory :user_event do | ||
user { build(:user) } | ||
data { | ||
{ | ||
canonical_id: SecureRandom.uuid, | ||
username: 'test-user', | ||
email: '[email protected]', | ||
} | ||
} | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters