-
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.
Merge branch 'master' into feature/add_web_specs
- Loading branch information
Showing
39 changed files
with
469 additions
and
325 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 was deleted.
Oops, something went wrong.
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,17 @@ | ||
module OutboxerIntegration | ||
class PublishMessageJob | ||
include Sidekiq::Job | ||
|
||
def perform(args) | ||
job_class_name = to_job_class_name(messageable_type: args['messageable_type']) | ||
job_class_name&.safe_constantize&.perform_async('event_id' => args['messageable_id']) | ||
end | ||
|
||
def to_job_class_name(messageable_type:) | ||
captures = messageable_type.match(/\A(?:(\w+)::)?(\w+)Event\z/)&.captures | ||
return if captures.nil? | ||
|
||
captures[0] ? "#{captures[0]}::#{captures[1]}Job" : "#{captures[1]}Job" | ||
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,9 @@ | ||
module OutboxerIntegration | ||
class TestStartedJob | ||
include Sidekiq::Job | ||
|
||
def perform(args) | ||
Test.complete(event_id: args['event_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,3 @@ | ||
class ApplicationRecord < ActiveRecord::Base | ||
self.abstract_class = true | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
module OutboxerIntegration | ||
class Test < ApplicationRecord | ||
self.table_name = 'outboxer_integration_tests' | ||
|
||
def self.start(user_id: nil, tenant_id: nil) | ||
transaction do | ||
test = create!(tenant_id: tenant_id) | ||
|
||
event = TestStartedEvent.create!( | ||
user_id: user_id, | ||
tenant_id: tenant_id, | ||
eventable: test, | ||
body: { | ||
'test' => { | ||
'id' => test.id } }) | ||
|
||
{ id: test.id, events: [{ id: event.id, type: event.type }] } | ||
end | ||
end | ||
|
||
def self.complete(event_id:) | ||
transaction do | ||
started_event = TestStartedEvent.find(event_id) | ||
test = started_event.eventable | ||
test.touch | ||
|
||
event = TestCompletedEvent.create!( | ||
user_id: started_event.user_id, | ||
tenant_id: started_event.tenant_id, | ||
eventable: test, | ||
body: { | ||
'test' => { | ||
'id' => test.id } }) | ||
|
||
{ id: test.id, events: [{ id: event.id, type: event.type }] } | ||
end | ||
end | ||
|
||
has_many :events, as: :eventable | ||
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,4 @@ | ||
module OutboxerIntegration | ||
class TestCompletedEvent < Event | ||
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,4 @@ | ||
module OutboxerIntegration | ||
class TestStartedEvent < Event | ||
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 |
---|---|---|
@@ -1,34 +1,15 @@ | ||
#!/usr/bin/env ruby | ||
|
||
require 'bundler/setup' | ||
require 'outboxer' | ||
|
||
options = { | ||
env: ENV.fetch('OUTBOXER_ENV', 'development'), | ||
buffer: ENV.fetch('OUTBOXER_BUFFER', 1000).to_i, | ||
concurrency: ENV.fetch('OUTBOXER_CONCURRENCY', 2).to_i, | ||
poll: ENV.fetch('OUTBOXER_POLL', 5.0).to_f, | ||
tick: ENV.fetch('OUTBOXER_TICK', 0.1).to_f, | ||
heartbeat: ENV.fetch('OUTBOXER_HEARTBEAT', 5.0).to_f, | ||
log_level: ENV.fetch('OUTBOXER_LOG_LEVEL', 'INFO'), | ||
} | ||
|
||
logger = Outboxer::Logger.new($stdout, level: options[:log_level]) | ||
require 'sidekiq' | ||
require 'outboxer' | ||
|
||
Outboxer::Publisher.publish( | ||
env: options[:env], | ||
buffer: options[:buffer], | ||
concurrency: options[:concurrency], | ||
poll: options[:poll], | ||
tick: options[:tick], | ||
heartbeat: options[:heartbeat], | ||
logger: logger | ||
) do |message| | ||
case message[:messageable_type] | ||
when 'Event' | ||
# TODO: publish message here | ||
require_relative '../app/jobs/outboxer_integration/publish_message_job' | ||
|
||
logger.info "Outboxer published message #{message[:id]} for "\ | ||
"#{message[:messageable_type]}::#{message[:messageable_id]}" | ||
end | ||
Outboxer::Publisher.publish do |message| | ||
OutboxerIntegration::PublishMessageJob.perform_async({ | ||
'message_id' => message[:id], | ||
'messageable_id' => message[:messageable_id], | ||
'messageable_type' => message[:messageable_type] }) | ||
end |
Oops, something went wrong.