-
-
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.
- Performance improvements for event dispatch
- Loading branch information
Showing
6 changed files
with
61 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class EventDispatcherJob < ApplicationJob | ||
queue_as :events | ||
|
||
def perform(event_name, timestamp, data) | ||
Rails.configuration.dispatcher.async_dispatcher.publish_event(event_name, timestamp, data) | ||
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
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,16 @@ | ||
require 'rails_helper' | ||
describe AsyncDispatcher do | ||
subject(:dispatcher) { described_class.new } | ||
|
||
let!(:conversation) { create(:conversation) } | ||
let(:event_name) { 'conversation.created' } | ||
let(:timestamp) { Time.zone.now } | ||
let(:event_data) { { conversation: conversation } } | ||
|
||
describe '#dispatch' do | ||
it 'enqueue job to dispatch event' do | ||
expect(EventDispatcherJob).to receive(:perform_later).with(event_name, timestamp, event_data).once | ||
dispatcher.dispatch(event_name, timestamp, event_data) | ||
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,22 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe EventDispatcherJob, type: :job do | ||
subject(:job) { described_class.perform_later(event_name, timestamp, event_data) } | ||
|
||
let!(:conversation) { create(:conversation) } | ||
let(:event_name) { 'conversation.created' } | ||
let(:timestamp) { Time.zone.now } | ||
let(:event_data) { { conversation: conversation } } | ||
|
||
it 'queues the job' do | ||
expect { job }.to have_enqueued_job(described_class) | ||
.with(event_name, timestamp, event_data) | ||
.on_queue('events') | ||
end | ||
|
||
it 'publishes event' do | ||
expect(Rails.configuration.dispatcher.async_dispatcher).to receive(:publish_event).with(event_name, timestamp, event_data).once | ||
event_dispatcher = described_class.new | ||
event_dispatcher.perform(event_name, timestamp, event_data) | ||
end | ||
end |