From 55c2ebe0610222f13ef5bdf6f3e7ed06e02b89c5 Mon Sep 17 00:00:00 2001 From: bedrock-adam Date: Wed, 11 Dec 2024 07:14:57 +1100 Subject: [PATCH 1/8] remove inline job queueing --- lib/accountify/contact.rb | 19 -------- lib/accountify/invoice.rb | 48 ------------------- lib/accountify/organisation.rb | 19 -------- spec/lib/accountify/contact/create_spec.rb | 11 ----- spec/lib/accountify/contact/delete_spec.rb | 11 ----- spec/lib/accountify/contact/update_spec.rb | 11 ----- spec/lib/accountify/invoice/delete_spec.rb | 11 ----- spec/lib/accountify/invoice/draft_spec.rb | 11 ----- spec/lib/accountify/invoice/issue_spec.rb | 11 ----- spec/lib/accountify/invoice/paid_spec.rb | 11 ----- spec/lib/accountify/invoice/update_spec.rb | 11 ----- spec/lib/accountify/invoice/void_spec.rb | 11 ----- .../accountify/organisation/create_spec.rb | 11 ----- .../accountify/organisation/delete_spec.rb | 11 ----- .../accountify/organisation/update_spec.rb | 11 ----- 15 files changed, 218 deletions(-) diff --git a/lib/accountify/contact.rb b/lib/accountify/contact.rb index c437cd1..79f6052 100644 --- a/lib/accountify/contact.rb +++ b/lib/accountify/contact.rb @@ -31,13 +31,6 @@ def create(user_id:, tenant_id:, 'email' => contact.email } }) end - EventCreatedJob.perform_async({ - 'user_id' => user_id, - 'tenant_id' => tenant_id, - 'id' => event.id, - 'type' => event.type, - 'organisation_id' => event.body['contact']['organisation_id'] }) - { id: contact.id, events: [{ id: event.id, type: event.type }] } end @@ -94,12 +87,6 @@ def update(user_id:, tenant_id:, id:, 'email' => contact.email } }) end - EventCreatedJob.perform_async({ - 'user_id' => user_id, - 'tenant_id' => tenant_id, - 'id' => event.id, - 'type' => event.type }) - { id: contact.id, events: [{ id: event.id, type: event.type }] } end @@ -126,12 +113,6 @@ def delete(user_id:, tenant_id:, id:, time: ::Time) 'deleted_at' => contact.deleted_at } }) end - EventCreatedJob.perform_async({ - 'user_id' => user_id, - 'tenant_id' => tenant_id, - 'id' => event.id, - 'type' => event.type }) - { id: contact.id, events: [{ id: event.id, type: event.type }] } end end diff --git a/lib/accountify/invoice.rb b/lib/accountify/invoice.rb index 5c9db0d..4cb361e 100644 --- a/lib/accountify/invoice.rb +++ b/lib/accountify/invoice.rb @@ -77,14 +77,6 @@ def draft(user_id:, tenant_id:, 'currency_code' => invoice.sub_total_currency_code } } }) end - EventCreatedJob.perform_async({ - 'user_id' => user_id, - 'tenant_id' => tenant_id, - 'id' => event.id, - 'type' => event.type, - 'occurred_at' => event.created_at.utc.iso8601, - 'organisation_id' => event.body['invoice']['organisation_id'] }) - { id: invoice.id, events: [{ id: event.id, type: event.type }] } end @@ -196,14 +188,6 @@ def update(user_id:, tenant_id:, id:, 'currency_code' => invoice.sub_total_currency_code } } }) end - EventCreatedJob.perform_async({ - 'user_id' => user_id, - 'tenant_id' => tenant_id, - 'id' => event.id, - 'type' => event.type, - 'occurred_at' => event.created_at.utc.iso8601, - 'organisation_id' => event.body['invoice']['organisation_id'] }) - { id: invoice.id, events: [{ id: event.id, type: event.type }] } end @@ -232,14 +216,6 @@ def delete(user_id:, tenant_id:, id:, time: ::Time) 'deleted_at' => invoice.deleted_at } } ) end - EventCreatedJob.perform_async({ - 'user_id' => user_id, - 'tenant_id' => tenant_id, - 'id' => event.id, - 'type' => event.type, - 'occurred_at' => event.created_at.utc.iso8601, - 'organisation_id' => event.body['invoice']['organisation_id'] }) - { id: invoice.id, events: [{ id: event.id, type: event.type }] } end @@ -272,14 +248,6 @@ def issue(user_id:, tenant_id:, id:, time: ::Time) 'organisation_id' => invoice.organisation_id } }) end - EventCreatedJob.perform_async({ - 'user_id' => user_id, - 'tenant_id' => tenant_id, - 'id' => event.id, - 'type' => event.type, - 'occurred_at' => event.created_at.utc.iso8601, - 'organisation_id' => event.body['invoice']['organisation_id'] }) - { id: invoice.id, events: [{ id: event.id, type: event.type }] } end @@ -313,14 +281,6 @@ def paid(user_id:, tenant_id:, id:, time: ::Time) 'organisation_id' => invoice.organisation_id } } ) end - EventCreatedJob.perform_async({ - 'user_id' => user_id, - 'tenant_id' => tenant_id, - 'id' => event.id, - 'type' => event.type, - 'occurred_at' => event.created_at.utc.iso8601, - 'organisation_id' => event.body['invoice']['organisation_id'] }) - { id: invoice.id, events: [{ id: event.id, type: event.type }] } end @@ -346,14 +306,6 @@ def void(user_id:, tenant_id:, id:, time: ::Time) 'organisation_id' => invoice.organisation_id } } ) end - EventCreatedJob.perform_async({ - 'user_id' => user_id, - 'tenant_id' => tenant_id, - 'id' => event.id, - 'type' => event.type, - 'occurred_at' => event.created_at.utc.iso8601, - 'organisation_id' => event.body['invoice']['organisation_id'] }) - { id: invoice.id, events: [{ id: event.id, type: event.type }] } end end diff --git a/lib/accountify/organisation.rb b/lib/accountify/organisation.rb index e488b61..1a68daa 100644 --- a/lib/accountify/organisation.rb +++ b/lib/accountify/organisation.rb @@ -23,13 +23,6 @@ def create(user_id:, tenant_id:, name:) 'name' => organisation.name } } ) end - EventCreatedJob.perform_async({ - 'user_id' => user_id, - 'tenant_id' => tenant_id, - 'id' => event.id, - 'type' => event.type, - 'organisation_id' => event['body']['organisation']['id'] }) - { id: organisation.id, events: [{ id: event.id, type: event.type }] } end @@ -77,12 +70,6 @@ def update(user_id:, tenant_id:, id:, name:) 'name' => organisation.name } }) end - EventCreatedJob.perform_async({ - 'user_id' => user_id, - 'tenant_id' => tenant_id, - 'id' => event.id, - 'type' => event.type }) - { id: organisation.id, events: [{ id: event.id, type: event.type }] } end @@ -109,12 +96,6 @@ def delete(user_id:, tenant_id:, id:, time: ::Time) 'deleted_at' => organisation.deleted_at } }) end - EventCreatedJob.perform_async({ - 'user_id' => user_id, - 'tenant_id' => tenant_id, - 'id' => event.id, - 'type' => event.type }) - { id: organisation.id, events: [{ id: event.id, type: event.type }] } end end diff --git a/spec/lib/accountify/contact/create_spec.rb b/spec/lib/accountify/contact/create_spec.rb index 5c3b680..cae0fe4 100644 --- a/spec/lib/accountify/contact/create_spec.rb +++ b/spec/lib/accountify/contact/create_spec.rb @@ -50,17 +50,6 @@ module Accountify it 'associates event with model' do expect(contact_model.events.last.id).to eq(contact[:events].last[:id]) end - - it 'queues event created job' do - expect(EventCreatedJob.jobs).to match([ - hash_including( - 'args' => [ - hash_including( - 'user_id' => user_id, - 'tenant_id' => tenant_id, - 'id' => contact[:events].last[:id], - 'type' => 'Accountify::Contact::CreatedEvent')])]) - end end end end diff --git a/spec/lib/accountify/contact/delete_spec.rb b/spec/lib/accountify/contact/delete_spec.rb index fadee37..e83bf13 100644 --- a/spec/lib/accountify/contact/delete_spec.rb +++ b/spec/lib/accountify/contact/delete_spec.rb @@ -52,17 +52,6 @@ module Accountify it 'associates event with model' do expect(contact_model.events.last.id).to eq contact[:events].last[:id] end - - it 'queues event created job' do - expect(EventCreatedJob.jobs).to match([ - hash_including( - 'args' => [ - hash_including( - 'user_id' => user_id, - 'tenant_id' => tenant_id, - 'id' => contact[:events].last[:id], - 'type' => 'Accountify::Contact::DeletedEvent')])]) - end end end end diff --git a/spec/lib/accountify/contact/update_spec.rb b/spec/lib/accountify/contact/update_spec.rb index eda8725..c4f989a 100644 --- a/spec/lib/accountify/contact/update_spec.rb +++ b/spec/lib/accountify/contact/update_spec.rb @@ -60,17 +60,6 @@ module Accountify it 'associates event with model' do expect(event_model.id).to eq(contact[:events].last[:id]) end - - it 'queues event created job' do - expect(EventCreatedJob.jobs).to match([ - hash_including( - 'args' => [ - hash_including( - 'user_id' => user_id, - 'tenant_id' => tenant_id, - 'id' => contact[:events].last[:id], - 'type' => 'Accountify::Contact::UpdatedEvent')])]) - end end end end diff --git a/spec/lib/accountify/invoice/delete_spec.rb b/spec/lib/accountify/invoice/delete_spec.rb index 41445c4..2ba0bd2 100644 --- a/spec/lib/accountify/invoice/delete_spec.rb +++ b/spec/lib/accountify/invoice/delete_spec.rb @@ -75,17 +75,6 @@ module Accountify it 'associates event with model' do expect(invoice_model.events.last.id).to eq(invoice[:events].last[:id]) end - - it 'queues event created job' do - expect(EventCreatedJob.jobs).to match([ - hash_including( - 'args' => [ - hash_including( - 'user_id' => user_id, - 'tenant_id' => tenant_id, - 'id' => invoice[:events].last[:id], - 'type' => 'Accountify::Invoice::DeletedEvent')])]) - end end end end diff --git a/spec/lib/accountify/invoice/draft_spec.rb b/spec/lib/accountify/invoice/draft_spec.rb index 293872d..ad12c83 100644 --- a/spec/lib/accountify/invoice/draft_spec.rb +++ b/spec/lib/accountify/invoice/draft_spec.rb @@ -97,17 +97,6 @@ module Accountify it 'associates event with model' do expect(invoice_model.events.last.id).to eq(invoice[:events].last[:id]) end - - it 'queues event created job' do - expect(EventCreatedJob.jobs).to match([ - hash_including( - 'args' => [ - hash_including( - 'user_id' => user_id, - 'tenant_id' => tenant_id, - 'id' => invoice[:events].last[:id], - 'type' => 'Accountify::Invoice::DraftedEvent')])]) - end end end end diff --git a/spec/lib/accountify/invoice/issue_spec.rb b/spec/lib/accountify/invoice/issue_spec.rb index 0a66071..9f8baf2 100644 --- a/spec/lib/accountify/invoice/issue_spec.rb +++ b/spec/lib/accountify/invoice/issue_spec.rb @@ -80,17 +80,6 @@ module Accountify it 'associates event with model' do expect(invoice_model.events.last.id).to eq(invoice[:events].last[:id]) end - - it 'queues event created job' do - expect(EventCreatedJob.jobs).to match([ - hash_including( - 'args' => [ - hash_including( - 'user_id' => user_id, - 'tenant_id' => tenant_id, - 'id' => invoice[:events].last[:id], - 'type' => 'Accountify::Invoice::IssuedEvent')])]) - end end end end diff --git a/spec/lib/accountify/invoice/paid_spec.rb b/spec/lib/accountify/invoice/paid_spec.rb index f58dc94..a8ed724 100644 --- a/spec/lib/accountify/invoice/paid_spec.rb +++ b/spec/lib/accountify/invoice/paid_spec.rb @@ -73,17 +73,6 @@ module Accountify it 'associates event with model' do expect(invoice_model.events.last.id).to eq(invoice[:events].last[:id]) end - - it 'queues event created job' do - expect(EventCreatedJob.jobs).to match([ - hash_including( - 'args' => [ - hash_including( - 'user_id' => user_id, - 'tenant_id' => tenant_id, - 'id' => invoice[:events].last[:id], - 'type' => 'Accountify::Invoice::PaidEvent')])]) - end end end end diff --git a/spec/lib/accountify/invoice/update_spec.rb b/spec/lib/accountify/invoice/update_spec.rb index 3cecaa7..3140863 100644 --- a/spec/lib/accountify/invoice/update_spec.rb +++ b/spec/lib/accountify/invoice/update_spec.rb @@ -141,17 +141,6 @@ module Accountify it 'associates event with model' do expect(invoice_model.events.last.id).to eq(invoice[:events].last[:id]) end - - it 'queues event created job' do - expect(EventCreatedJob.jobs).to match([ - hash_including( - 'args' => [ - hash_including( - 'user_id' => user_id, - 'tenant_id' => tenant_id, - 'id' => invoice[:events].last[:id], - 'type' => 'Accountify::Invoice::UpdatedEvent')])]) - end end end end diff --git a/spec/lib/accountify/invoice/void_spec.rb b/spec/lib/accountify/invoice/void_spec.rb index bbc7f02..f547080 100644 --- a/spec/lib/accountify/invoice/void_spec.rb +++ b/spec/lib/accountify/invoice/void_spec.rb @@ -75,17 +75,6 @@ module Accountify it 'associates event with model' do expect(invoice_model.events.last.id).to eq(invoice[:events].last[:id]) end - - it 'queues event created job' do - expect(EventCreatedJob.jobs).to match([ - hash_including( - 'args' => [ - hash_including( - 'user_id' => user_id, - 'tenant_id' => tenant_id, - 'id' => invoice[:events].last[:id], - 'type' => 'Accountify::Invoice::VoidedEvent')])]) - end end end end diff --git a/spec/lib/accountify/organisation/create_spec.rb b/spec/lib/accountify/organisation/create_spec.rb index 68cd932..ef371ba 100644 --- a/spec/lib/accountify/organisation/create_spec.rb +++ b/spec/lib/accountify/organisation/create_spec.rb @@ -37,17 +37,6 @@ module Accountify it 'associates event with model' do expect(organisation_model.events.last.id).to eq(organisation[:events].last[:id]) end - - it 'queues event created job' do - expect(EventCreatedJob.jobs).to match([ - hash_including( - 'args' => [ - hash_including( - 'user_id' => user_id, - 'tenant_id' => tenant_id, - 'id' => organisation[:events].last[:id], - 'type' => 'Accountify::Organisation::CreatedEvent')])]) - end end end end diff --git a/spec/lib/accountify/organisation/delete_spec.rb b/spec/lib/accountify/organisation/delete_spec.rb index 0c280b4..624d177 100644 --- a/spec/lib/accountify/organisation/delete_spec.rb +++ b/spec/lib/accountify/organisation/delete_spec.rb @@ -41,17 +41,6 @@ module Accountify it 'associates event with model' do expect(organisation_model.events.last.id).to eq organisation[:events].last[:id] end - - it 'queues event created job' do - expect(EventCreatedJob.jobs).to match([ - hash_including( - 'args' => [ - hash_including( - 'user_id' => user_id, - 'tenant_id' => tenant_id, - 'id' => organisation[:events].last[:id], - 'type' => 'Accountify::Organisation::DeletedEvent')])]) - end end end end diff --git a/spec/lib/accountify/organisation/update_spec.rb b/spec/lib/accountify/organisation/update_spec.rb index 0935861..0bd1bf9 100644 --- a/spec/lib/accountify/organisation/update_spec.rb +++ b/spec/lib/accountify/organisation/update_spec.rb @@ -41,17 +41,6 @@ module Accountify it 'associates event with model' do expect(event_model.id).to eq organisation[:events].last[:id] end - - it 'queues event created job' do - expect(EventCreatedJob.jobs).to match([ - hash_including( - 'args' => [ - hash_including( - 'user_id' => user_id, - 'tenant_id' => tenant_id, - 'id' => organisation[:events].last[:id], - 'type' => 'Accountify::Organisation::UpdatedEvent')])]) - end end end end From 51807f37f02a290a891795422d33abc1d0325a5b Mon Sep 17 00:00:00 2001 From: bedrock-adam Date: Sat, 14 Dec 2024 19:02:33 +1100 Subject: [PATCH 2/8] update to include publisher --- script/accountify/invoice/test_lifecycle.rb | 23 ++++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/script/accountify/invoice/test_lifecycle.rb b/script/accountify/invoice/test_lifecycle.rb index 0baaf43..9291bdd 100644 --- a/script/accountify/invoice/test_lifecycle.rb +++ b/script/accountify/invoice/test_lifecycle.rb @@ -69,9 +69,13 @@ Accountify::Invoice.delete(user_id: user_id, tenant_id: tenant_id, id: invoice[:id]) -puts "Starting Sidekiq..." -sidekiq_cmd = "bundle exec sidekiq -r ./config/sidekiq.rb" -sidekiq_process = IO.popen(sidekiq_cmd) +puts "starting sidekiq server..." +sidekiq_server_cmd = "bundle exec sidekiq -r ./config/sidekiq.rb" +sidekiq_server_process = IO.popen(sidekiq_server_cmd) + +puts "starting outboxer publisher..." +outboxer_publisher_cmd = "bin/outboxer_publisher" +outboxer_publisher_process = IO.popen(outboxer_publisher_cmd) begin invoice_status_summary = nil @@ -88,18 +92,21 @@ rescue Accountify::NotFound sleep 1 - puts "Invoice status summary not found. Retrying (Attempt #{attempts}/#{max_attempts})..." + puts "invoice status summary not found. Retrying (Attempt #{attempts}/#{max_attempts})..." end end if invoice_status_summary.nil? - raise Accountify::NotFound, "Invoice status summary not found after #{max_attempts} attempts." + raise Accountify::NotFound, "invoice status summary not found after #{max_attempts} attempts" end ensure - puts "Stopping Sidekiq..." + puts "stopping outboxer publisher..." + Process.kill("TERM", outboxer_pubisher_process.pid) + Process.wait(outboxer_publisher_process.pid) - Process.kill("TERM", sidekiq_process.pid) - Process.wait(sidekiq_process.pid) + puts "stopping sidekiq server..." + Process.kill("TERM", sidekiq_server_process.pid) + Process.wait(sidekiq_server_process.pid) end # bundle exec ruby script/accountify/invoice/test_lifecycle.rb From 87869b090006d5867bceda48664aface3588db9d Mon Sep 17 00:00:00 2001 From: bedrock-adam Date: Sat, 14 Dec 2024 21:13:31 +1100 Subject: [PATCH 3/8] commit changes --- Gemfile | 2 + Gemfile.lock | 9 ++ app/jobs/event_created_job.rb | 100 ++++++++++-------- bin/outboxer_publisher | 38 +++++++ ...20241214080817_create_outboxer_settings.rb | 18 ++++ ...20241214080818_create_outboxer_messages.rb | 40 +++++++ ...241214080819_create_outboxer_exceptions.rb | 20 ++++ .../20241214080820_create_outboxer_frames.rb | 16 +++ ...241214080821_create_outboxer_publishers.rb | 18 ++++ .../20241214080822_create_outboxer_signals.rb | 16 +++ db/schema.rb | 61 ++++++++++- lib/accountify/invoice.rb | 2 +- lib/event.rb | 6 ++ script/accountify/invoice/test_lifecycle.rb | 2 +- 14 files changed, 298 insertions(+), 50 deletions(-) create mode 100755 bin/outboxer_publisher create mode 100644 db/migrate/20241214080817_create_outboxer_settings.rb create mode 100644 db/migrate/20241214080818_create_outboxer_messages.rb create mode 100644 db/migrate/20241214080819_create_outboxer_exceptions.rb create mode 100644 db/migrate/20241214080820_create_outboxer_frames.rb create mode 100644 db/migrate/20241214080821_create_outboxer_publishers.rb create mode 100644 db/migrate/20241214080822_create_outboxer_signals.rb diff --git a/Gemfile b/Gemfile index 86b6a54..83f9f3d 100644 --- a/Gemfile +++ b/Gemfile @@ -14,6 +14,8 @@ gem "activerecord" gem "sidekiq" +gem 'outboxer', git: 'https://github.com/fast-programmer/outboxer.git', branch: 'master' + group :development do end diff --git a/Gemfile.lock b/Gemfile.lock index 7da0472..4fa7412 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,3 +1,11 @@ +GIT + remote: https://github.com/fast-programmer/outboxer.git + revision: 70e02414ed68f58e864f738651dfe4a14b947569 + branch: master + specs: + outboxer (1.0.0.pre.beta) + activerecord (>= 7.0.8.6) + GEM remote: https://rubygems.org/ specs: @@ -212,6 +220,7 @@ DEPENDENCIES activerecord database_cleaner-active_record factory_bot_rails + outboxer! pg pry-byebug puma diff --git a/app/jobs/event_created_job.rb b/app/jobs/event_created_job.rb index 1155992..efee7f0 100644 --- a/app/jobs/event_created_job.rb +++ b/app/jobs/event_created_job.rb @@ -1,50 +1,56 @@ -class EventCreatedJob - include Sidekiq::Job - - sidekiq_options queue: 'events', retry: false, backtrace: true - - def perform(args) - case args['type'] - when 'Accountify::Organisation::CreatedEvent' - Accountify::InvoiceStatusSummary::GenerateJob.perform_async({ - 'tenant_id' => args['tenant_id'], - 'organisation_id' => args['organisation_id'] }) - - when 'Accountify::Invoice::DraftedEvent' - Accountify::InvoiceStatusSummary::RegenerateJob.perform_async({ - 'tenant_id' => args['tenant_id'], - 'organisation_id' => args['organisation_id'], - 'invoice_updated_at' => args['occurred_at'] }) - - when 'Accountify::Invoice::UpdatedEvent' - Accountify::InvoiceStatusSummary::RegenerateJob.perform_async({ - 'tenant_id' => args['tenant_id'], - 'organisation_id' => args['organisation_id'], - 'invoice_updated_at' => args['occurred_at'] }) - - when 'Accountify::Invoice::IssuedEvent' - Accountify::InvoiceStatusSummary::RegenerateJob.perform_async({ - 'tenant_id' => args['tenant_id'], - 'organisation_id' => args['organisation_id'], - 'invoice_updated_at' => args['occurred_at'] }) - - when 'Accountify::Invoice::PaidEvent' - Accountify::InvoiceStatusSummary::RegenerateJob.perform_async({ - 'tenant_id' => args['tenant_id'], - 'organisation_id' => args['organisation_id'], - 'invoice_updated_at' => args['occurred_at'] }) - - when 'Accountify::Invoice::VoidedEvent' - Accountify::InvoiceStatusSummary::RegenerateJob.perform_async({ - 'tenant_id' => args['tenant_id'], - 'organisation_id' => args['organisation_id'], - 'invoice_updated_at' => args['occurred_at'] }) - - when 'Accountify::Invoice::DeletedEvent' - Accountify::InvoiceStatusSummary::RegenerateJob.perform_async({ - 'tenant_id' => args['tenant_id'], - 'organisation_id' => args['organisation_id'], - 'invoice_updated_at' => args['occurred_at'] }) +module OutboxerIntegration + module Message + class PublishJob + include Sidekiq::Job + + sidekiq_options queue: 'events', retry: false, backtrace: true + + def perform(args) + messageable = args['messageable_type'].constantize.find(args['messageable_id']) + + case messageable + when Accountify::Organisation::CreatedEvent + Accountify::InvoiceStatusSummary::GenerateJob.perform_async({ + 'tenant_id' => messageable.tenant_id, + 'organisation_id' => messageable.body['organisation_id'] }) + + when Accountify::Invoice::DraftedEvent + Accountify::InvoiceStatusSummary::RegenerateJob.perform_async({ + 'tenant_id' => messageable.tenant_id, + 'organisation_id' => messageable.body['organisation_id'], + 'invoice_updated_at' => messageable.body['occurred_at'] }) + + when Accountify::Invoice::UpdatedEvent + Accountify::InvoiceStatusSummary::RegenerateJob.perform_async({ + 'tenant_id' => messageable.tenant_id, + 'organisation_id' => messageable.body['organisation_id'], + 'invoice_updated_at' => messageable.body['occurred_at'] }) + + when Accountify::Invoice::IssuedEvent + Accountify::InvoiceStatusSummary::RegenerateJob.perform_async({ + 'tenant_id' => messageable.tenant_id, + 'organisation_id' => messageable.body['organisation_id'], + 'invoice_updated_at' => messageable.body['occurred_at'] }) + + when Accountify::Invoice::PaidEvent + Accountify::InvoiceStatusSummary::RegenerateJob.perform_async({ + 'tenant_id' => messageable.tenant_id, + 'organisation_id' => messageable.body['organisation_id'], + 'invoice_updated_at' => messageable.body['occurred_at'] }) + + when Accountify::Invoice::VoidedEvent + Accountify::InvoiceStatusSummary::RegenerateJob.perform_async({ + 'tenant_id' => messageable.tenant_id, + 'organisation_id' => messageable.body['organisation_id'], + 'invoice_updated_at' => messageable.body['occurred_at'] }) + + when Accountify::Invoice::DeletedEvent + Accountify::InvoiceStatusSummary::RegenerateJob.perform_async({ + 'tenant_id' => messageable.tenant_id, + 'organisation_id' => messageable.body['organisation_id'], + 'invoice_updated_at' => messageable.body['occurred_at'] }) + end + end end end end diff --git a/bin/outboxer_publisher b/bin/outboxer_publisher new file mode 100755 index 0000000..af11e16 --- /dev/null +++ b/bin/outboxer_publisher @@ -0,0 +1,38 @@ +#!/usr/bin/env ruby + +require 'bundler/setup' +require 'sidekiq' +require 'outboxer' + +require_relative '../app/jobs/event_created_job' + +options = { + env: ENV.fetch('OUTBOXER_ENV', 'development'), + buffer: ENV.fetch('OUTBOXER_BUFFER', 1000).to_i, + concurrency: ENV.fetch('OUTBOXER_CONCURRENCY', 1).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'), + redis_url: ENV.fetch('OUTBOXER_REDIS_URL', 'redis://localhost:6379/0') +} + +Sidekiq.configure_client do |config| + config.redis = { url: options[:redis_url], size: options[:concurrency] } +end + +logger = Outboxer::Logger.new($stdout, level: options[:log_level]) + +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| + OutboxerIntegration::Message::PublishJob.perform_async({ + 'messageable_id' => message[:messageable_id], + 'messageable_type' => message[:messageable_type] }) +end diff --git a/db/migrate/20241214080817_create_outboxer_settings.rb b/db/migrate/20241214080817_create_outboxer_settings.rb new file mode 100644 index 0000000..e1e43c3 --- /dev/null +++ b/db/migrate/20241214080817_create_outboxer_settings.rb @@ -0,0 +1,18 @@ +class CreateOutboxerSettings < ActiveRecord::Migration[6.1] + def up + ActiveRecord::Base.transaction do + create_table :outboxer_settings do |t| + t.string :name, limit: 255, null: false + t.string :value, limit: 255, null: false + + t.timestamps + end + + add_index :outboxer_settings, :name, unique: true + end + end + + def down + drop_table :outboxer_settings + end +end diff --git a/db/migrate/20241214080818_create_outboxer_messages.rb b/db/migrate/20241214080818_create_outboxer_messages.rb new file mode 100644 index 0000000..88a3d52 --- /dev/null +++ b/db/migrate/20241214080818_create_outboxer_messages.rb @@ -0,0 +1,40 @@ +class CreateOutboxerMessages < ActiveRecord::Migration[6.1] + def up + create_table :outboxer_messages do |t| + t.string :status, limit: 255, null: false + + t.string :messageable_id, limit: 255, null: false + t.string :messageable_type, limit: 255, null: false + + t.datetime :queued_at, precision: 6, null: false + + t.datetime :buffered_at, precision: 6 + + t.datetime :publishing_at, precision: 6 + + t.datetime :updated_at, precision: 6, null: false + + t.bigint :publisher_id + t.string :publisher_name, limit: 263 # 255 (hostname) + 1 (colon) + 7 (pid) + end + + # messages by status count + add_index :outboxer_messages, :status, name: 'idx_outboxer_status' + + # messages by status latency + add_index :outboxer_messages, [:status, :updated_at], + name: 'idx_outboxer_status_updated_at' + + # publisher latency + add_index :outboxer_messages, [:publisher_id, :updated_at], + name: 'idx_outboxer_pub_id_updated_at' + + # publisher throughput + add_index :outboxer_messages, [:status, :publisher_id, :updated_at], + name: 'idx_outboxer_status_pub_id_updated_at' + end + + def down + drop_table :outboxer_messages if table_exists?(:outboxer_messages) + end +end diff --git a/db/migrate/20241214080819_create_outboxer_exceptions.rb b/db/migrate/20241214080819_create_outboxer_exceptions.rb new file mode 100644 index 0000000..369215b --- /dev/null +++ b/db/migrate/20241214080819_create_outboxer_exceptions.rb @@ -0,0 +1,20 @@ +class CreateOutboxerExceptions < ActiveRecord::Migration[6.1] + def up + ActiveRecord::Base.transaction do + create_table :outboxer_exceptions do |t| + t.references :message, foreign_key: { to_table: :outboxer_messages }, null: false + + t.string :class_name, limit: 255, null: false + t.text :message_text, null: false + + t.timestamps + end + + remove_column :outboxer_exceptions, :updated_at + end + end + + def down + drop_table :outboxer_exceptions if table_exists?(:outboxer_exceptions) + end +end diff --git a/db/migrate/20241214080820_create_outboxer_frames.rb b/db/migrate/20241214080820_create_outboxer_frames.rb new file mode 100644 index 0000000..1e7f7ec --- /dev/null +++ b/db/migrate/20241214080820_create_outboxer_frames.rb @@ -0,0 +1,16 @@ +class CreateOutboxerFrames < ActiveRecord::Migration[6.1] + def up + create_table :outboxer_frames do |t| + t.references :exception, foreign_key: { to_table: :outboxer_exceptions }, null: false + + t.integer :index, null: false + t.text :text, null: false + + t.index [:exception_id, :index], unique: true + end + end + + def down + drop_table :outboxer_frames if table_exists?(:outboxer_frames) + end +end diff --git a/db/migrate/20241214080821_create_outboxer_publishers.rb b/db/migrate/20241214080821_create_outboxer_publishers.rb new file mode 100644 index 0000000..f5c7a4e --- /dev/null +++ b/db/migrate/20241214080821_create_outboxer_publishers.rb @@ -0,0 +1,18 @@ +class CreateOutboxerPublishers < ActiveRecord::Migration[6.1] + def up + ActiveRecord::Base.transaction do + create_table :outboxer_publishers do |t| + t.string :name, limit: 263, null: false # 255 (hostname) + 1 (colon) + 7 (pid) + t.string :status, limit: 255, null: false + t.json :settings, null: false + t.json :metrics, null: false + + t.timestamps + end + end + end + + def down + drop_table :outboxer_publishers + end +end diff --git a/db/migrate/20241214080822_create_outboxer_signals.rb b/db/migrate/20241214080822_create_outboxer_signals.rb new file mode 100644 index 0000000..747d475 --- /dev/null +++ b/db/migrate/20241214080822_create_outboxer_signals.rb @@ -0,0 +1,16 @@ +class CreateOutboxerSignals < ActiveRecord::Migration[6.1] + def up + ActiveRecord::Base.transaction do + create_table :outboxer_signals do |t| + t.string :name, limit: 9, null: false + t.references :publisher, foreign_key: { to_table: :outboxer_publishers }, null: false + + t.datetime :created_at, null: false + end + end + end + + def down + drop_table :outboxer_signals + end +end diff --git a/db/schema.rb b/db/schema.rb index 4c88e5a..d958d69 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.0].define(version: 2024_07_06_053510) do +ActiveRecord::Schema[7.0].define(version: 2024_12_14_080822) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -94,9 +94,68 @@ t.index ["eventable_type", "eventable_id"], name: "index_events_on_eventable_type_and_eventable_id" end + create_table "outboxer_exceptions", force: :cascade do |t| + t.bigint "message_id", null: false + t.string "class_name", limit: 255, null: false + t.text "message_text", null: false + t.datetime "created_at", null: false + t.index ["message_id"], name: "index_outboxer_exceptions_on_message_id" + end + + create_table "outboxer_frames", force: :cascade do |t| + t.bigint "exception_id", null: false + t.integer "index", null: false + t.text "text", null: false + t.index ["exception_id", "index"], name: "index_outboxer_frames_on_exception_id_and_index", unique: true + t.index ["exception_id"], name: "index_outboxer_frames_on_exception_id" + end + + create_table "outboxer_messages", force: :cascade do |t| + t.string "status", limit: 255, null: false + t.string "messageable_id", limit: 255, null: false + t.string "messageable_type", limit: 255, null: false + t.datetime "queued_at", null: false + t.datetime "buffered_at" + t.datetime "publishing_at" + t.datetime "updated_at", null: false + t.bigint "publisher_id" + t.string "publisher_name", limit: 263 + t.index ["publisher_id", "updated_at"], name: "idx_outboxer_pub_id_updated_at" + t.index ["status", "publisher_id", "updated_at"], name: "idx_outboxer_status_pub_id_updated_at" + t.index ["status", "updated_at"], name: "idx_outboxer_status_updated_at" + t.index ["status"], name: "idx_outboxer_status" + end + + create_table "outboxer_publishers", force: :cascade do |t| + t.string "name", limit: 263, null: false + t.string "status", limit: 255, null: false + t.json "settings", null: false + t.json "metrics", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + + create_table "outboxer_settings", force: :cascade do |t| + t.string "name", limit: 255, null: false + t.string "value", limit: 255, null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["name"], name: "index_outboxer_settings_on_name", unique: true + end + + create_table "outboxer_signals", force: :cascade do |t| + t.string "name", limit: 9, null: false + t.bigint "publisher_id", null: false + t.datetime "created_at", precision: nil, null: false + t.index ["publisher_id"], name: "index_outboxer_signals_on_publisher_id" + end + add_foreign_key "accountify_contacts", "accountify_organisations", column: "organisation_id" add_foreign_key "accountify_invoice_line_items", "accountify_invoices", column: "invoice_id" add_foreign_key "accountify_invoice_status_summaries", "accountify_organisations", column: "organisation_id" add_foreign_key "accountify_invoices", "accountify_contacts", column: "contact_id" add_foreign_key "accountify_invoices", "accountify_organisations", column: "organisation_id" + add_foreign_key "outboxer_exceptions", "outboxer_messages", column: "message_id" + add_foreign_key "outboxer_frames", "outboxer_exceptions", column: "exception_id" + add_foreign_key "outboxer_signals", "outboxer_publishers", column: "publisher_id" end diff --git a/lib/accountify/invoice.rb b/lib/accountify/invoice.rb index 4cb361e..8dd0c59 100644 --- a/lib/accountify/invoice.rb +++ b/lib/accountify/invoice.rb @@ -9,7 +9,7 @@ module Status VOIDED = 'voided' end - class DraftedEvent < Event; end + class DraftedEvent < Models::Event; end def draft(user_id:, tenant_id:, organisation_id:, contact_id:, diff --git a/lib/event.rb b/lib/event.rb index 8269f43..1b6e909 100644 --- a/lib/event.rb +++ b/lib/event.rb @@ -9,4 +9,10 @@ class Event < ActiveRecord::Base # associations belongs_to :eventable, polymorphic: true + + # callbacks + + after_create do |event| + Outboxer::Message.queue(messageable: event) + end end diff --git a/script/accountify/invoice/test_lifecycle.rb b/script/accountify/invoice/test_lifecycle.rb index 9291bdd..8371856 100644 --- a/script/accountify/invoice/test_lifecycle.rb +++ b/script/accountify/invoice/test_lifecycle.rb @@ -101,7 +101,7 @@ end ensure puts "stopping outboxer publisher..." - Process.kill("TERM", outboxer_pubisher_process.pid) + Process.kill("TERM", outboxer_publisher_process.pid) Process.wait(outboxer_publisher_process.pid) puts "stopping sidekiq server..." From 67ed246d1f436455d65132be37b8d8afb8a3e283 Mon Sep 17 00:00:00 2001 From: bedrock-adam Date: Sat, 14 Dec 2024 22:25:29 +1100 Subject: [PATCH 4/8] fix tests --- bin/outboxer_publisher | 2 +- lib/accountify/invoice.rb | 2 +- spec/integration/accountify/invoice/test_lifecycle_spec.rb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/bin/outboxer_publisher b/bin/outboxer_publisher index af11e16..de38267 100755 --- a/bin/outboxer_publisher +++ b/bin/outboxer_publisher @@ -4,7 +4,7 @@ require 'bundler/setup' require 'sidekiq' require 'outboxer' -require_relative '../app/jobs/event_created_job' +require_relative '../app/jobs/outboxer_integration/message/publish_job' options = { env: ENV.fetch('OUTBOXER_ENV', 'development'), diff --git a/lib/accountify/invoice.rb b/lib/accountify/invoice.rb index 8dd0c59..4cb361e 100644 --- a/lib/accountify/invoice.rb +++ b/lib/accountify/invoice.rb @@ -9,7 +9,7 @@ module Status VOIDED = 'voided' end - class DraftedEvent < Models::Event; end + class DraftedEvent < Event; end def draft(user_id:, tenant_id:, organisation_id:, contact_id:, diff --git a/spec/integration/accountify/invoice/test_lifecycle_spec.rb b/spec/integration/accountify/invoice/test_lifecycle_spec.rb index 90c1467..c061db2 100644 --- a/spec/integration/accountify/invoice/test_lifecycle_spec.rb +++ b/spec/integration/accountify/invoice/test_lifecycle_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' RSpec.describe 'Invoice Lifecycle', type: :integration do - xit 'transitions as expected' do + it 'transitions as expected' do Sidekiq::Testing.disable! begin From 5f2dd8a71b4e4b4dd8969924000436b314656922 Mon Sep 17 00:00:00 2001 From: bedrock-adam Date: Sat, 14 Dec 2024 22:28:09 +1100 Subject: [PATCH 5/8] reduce diff --- script/accountify/invoice/test_lifecycle.rb | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/script/accountify/invoice/test_lifecycle.rb b/script/accountify/invoice/test_lifecycle.rb index 8371856..eaafe7e 100644 --- a/script/accountify/invoice/test_lifecycle.rb +++ b/script/accountify/invoice/test_lifecycle.rb @@ -1,7 +1,7 @@ -require_relative '../../../config/environment' - require 'open3' +require_relative '../../../config/environment' + user_id = 123 tenant_id = 456 @@ -69,11 +69,11 @@ Accountify::Invoice.delete(user_id: user_id, tenant_id: tenant_id, id: invoice[:id]) -puts "starting sidekiq server..." +puts "Starting sidekiq server..." sidekiq_server_cmd = "bundle exec sidekiq -r ./config/sidekiq.rb" sidekiq_server_process = IO.popen(sidekiq_server_cmd) -puts "starting outboxer publisher..." +puts "Starting outboxer publisher..." outboxer_publisher_cmd = "bin/outboxer_publisher" outboxer_publisher_process = IO.popen(outboxer_publisher_cmd) @@ -92,19 +92,19 @@ rescue Accountify::NotFound sleep 1 - puts "invoice status summary not found. Retrying (Attempt #{attempts}/#{max_attempts})..." + puts "Invoice status summary not found. Retrying (Attempt #{attempts}/#{max_attempts})..." end end if invoice_status_summary.nil? - raise Accountify::NotFound, "invoice status summary not found after #{max_attempts} attempts" + raise Accountify::NotFound, "Invoice status summary not found after #{max_attempts} attempts" end ensure - puts "stopping outboxer publisher..." + puts "Stopping outboxer publisher..." Process.kill("TERM", outboxer_publisher_process.pid) Process.wait(outboxer_publisher_process.pid) - puts "stopping sidekiq server..." + puts "Stopping sidekiq server..." Process.kill("TERM", sidekiq_server_process.pid) Process.wait(sidekiq_server_process.pid) end From 22ddbe3c3ae05c25c28465f74ef0f29da66a5368 Mon Sep 17 00:00:00 2001 From: bedrock-adam Date: Sat, 14 Dec 2024 22:37:08 +1100 Subject: [PATCH 6/8] fix build --- script/accountify/invoice/test_lifecycle.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/script/accountify/invoice/test_lifecycle.rb b/script/accountify/invoice/test_lifecycle.rb index eaafe7e..a198393 100644 --- a/script/accountify/invoice/test_lifecycle.rb +++ b/script/accountify/invoice/test_lifecycle.rb @@ -74,7 +74,8 @@ sidekiq_server_process = IO.popen(sidekiq_server_cmd) puts "Starting outboxer publisher..." -outboxer_publisher_cmd = "bin/outboxer_publisher" +outboxer_publisher_env = ENV['RAILS_ENV'] || 'development' +outboxer_publisher_cmd = "OUTBOXER_ENV=#{outboxer_publisher_env} bin/outboxer_publisher" outboxer_publisher_process = IO.popen(outboxer_publisher_cmd) begin From c206effe27997213fed33a67aa672c561f25cbc7 Mon Sep 17 00:00:00 2001 From: bedrock-adam Date: Sun, 15 Dec 2024 13:40:02 +1100 Subject: [PATCH 7/8] fail tests --- script/accountify/invoice/test_lifecycle.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/script/accountify/invoice/test_lifecycle.rb b/script/accountify/invoice/test_lifecycle.rb index a198393..f201d35 100644 --- a/script/accountify/invoice/test_lifecycle.rb +++ b/script/accountify/invoice/test_lifecycle.rb @@ -69,13 +69,14 @@ Accountify::Invoice.delete(user_id: user_id, tenant_id: tenant_id, id: invoice[:id]) +outboxer_env = ENV['OUTBOXER_ENV'] || ENV['RAILS_ENV'] || 'development' + puts "Starting sidekiq server..." -sidekiq_server_cmd = "bundle exec sidekiq -r ./config/sidekiq.rb" +sidekiq_server_cmd = "OUTBOXER_ENV=#{outboxer_env} bundle exec sidekiq -r ./config/sidekiq.rb" sidekiq_server_process = IO.popen(sidekiq_server_cmd) puts "Starting outboxer publisher..." -outboxer_publisher_env = ENV['RAILS_ENV'] || 'development' -outboxer_publisher_cmd = "OUTBOXER_ENV=#{outboxer_publisher_env} bin/outboxer_publisher" +outboxer_publisher_cmd = "OUTBOXER_ENV=#{outboxer_env} bin/outboxer_publisher" outboxer_publisher_process = IO.popen(outboxer_publisher_cmd) begin From 2d013474c11952cbc94f98c39dfab82bdb93cf30 Mon Sep 17 00:00:00 2001 From: bedrock-adam Date: Sun, 15 Dec 2024 14:26:49 +1100 Subject: [PATCH 8/8] pass build --- .github/workflows/ci.yml | 10 ++++++++++ app/jobs/outboxer_integration/message/publish_job.rb | 12 ++++++------ bin/outboxer_publisher | 4 ++-- script/accountify/invoice/test_lifecycle.rb | 6 +++--- .../outboxer_integration/message/publish_job_spec.rb | 12 ++++++------ 5 files changed, 27 insertions(+), 17 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 943b111..d289eb5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -65,5 +65,15 @@ jobs: bundle exec rails db:create bundle exec rails db:schema:load + # - name: add Outboxer + # run: | + # echo "gem 'outboxer', git: 'https://github.com/fast-programmer/outboxer.git', branch: 'master'" >> Gemfile + # bundle install + # bin/rails g outboxer:schema + # bin/rake db:migrate + # bin/rake outboxer:db:seed + # bin/rails g outboxer:sidekiq_publisher + # echo "$(sed '$d' lib/event.rb)\n\n # callbacks\n\n after_create do |event|\n Outboxer::Message.queue(messageable: event)\n end\nend" > lib/event.rb + - name: Run tests run: bundle exec rspec diff --git a/app/jobs/outboxer_integration/message/publish_job.rb b/app/jobs/outboxer_integration/message/publish_job.rb index ab24f92..235b90e 100644 --- a/app/jobs/outboxer_integration/message/publish_job.rb +++ b/app/jobs/outboxer_integration/message/publish_job.rb @@ -19,37 +19,37 @@ def perform(args) when 'Accountify::Invoice::DraftedEvent' Accountify::InvoiceStatusSummary::RegenerateJob.perform_async({ 'tenant_id' => messageable.tenant_id, - 'organisation_id' => messageable.body['organisation']['id'], + 'organisation_id' => messageable.body['invoice']['organisation_id'], 'invoice_updated_at' => messageable.created_at.utc.iso8601 }) when 'Accountify::Invoice::UpdatedEvent' Accountify::InvoiceStatusSummary::RegenerateJob.perform_async({ 'tenant_id' => messageable.tenant_id, - 'organisation_id' => messageable.body['organisation']['id'], + 'organisation_id' => messageable.body['invoice']['organisation_id'], 'invoice_updated_at' => messageable.created_at.utc.iso8601 }) when 'Accountify::Invoice::IssuedEvent' Accountify::InvoiceStatusSummary::RegenerateJob.perform_async({ 'tenant_id' => messageable.tenant_id, - 'organisation_id' => messageable.body['organisation']['id'], + 'organisation_id' => messageable.body['invoice']['organisation_id'], 'invoice_updated_at' => messageable.created_at.utc.iso8601 }) when 'Accountify::Invoice::PaidEvent' Accountify::InvoiceStatusSummary::RegenerateJob.perform_async({ 'tenant_id' => messageable.tenant_id, - 'organisation_id' => messageable.body['organisation']['id'], + 'organisation_id' => messageable.body['invoice']['organisation_id'], 'invoice_updated_at' => messageable.created_at.utc.iso8601 }) when 'Accountify::Invoice::VoidedEvent' Accountify::InvoiceStatusSummary::RegenerateJob.perform_async({ 'tenant_id' => messageable.tenant_id, - 'organisation_id' => messageable.body['organisation']['id'], + 'organisation_id' => messageable.body['invoice']['organisation_id'], 'invoice_updated_at' => messageable.created_at.utc.iso8601 }) when 'Accountify::Invoice::DeletedEvent' Accountify::InvoiceStatusSummary::RegenerateJob.perform_async({ 'tenant_id' => messageable.tenant_id, - 'organisation_id' => messageable.body['organisation']['id'], + 'organisation_id' => messageable.body['invoice']['organisation_id'], 'invoice_updated_at' => messageable.created_at.utc.iso8601 }) end end diff --git a/bin/outboxer_publisher b/bin/outboxer_publisher index de38267..b9cd10e 100755 --- a/bin/outboxer_publisher +++ b/bin/outboxer_publisher @@ -33,6 +33,6 @@ Outboxer::Publisher.publish( logger: logger ) do |message| OutboxerIntegration::Message::PublishJob.perform_async({ - 'messageable_id' => message[:messageable_id], - 'messageable_type' => message[:messageable_type] }) + 'messageable_id' => message[:messageable_id], 'messageable_type' => message[:messageable_type] + }) end diff --git a/script/accountify/invoice/test_lifecycle.rb b/script/accountify/invoice/test_lifecycle.rb index f201d35..93e5e70 100644 --- a/script/accountify/invoice/test_lifecycle.rb +++ b/script/accountify/invoice/test_lifecycle.rb @@ -71,12 +71,12 @@ outboxer_env = ENV['OUTBOXER_ENV'] || ENV['RAILS_ENV'] || 'development' -puts "Starting sidekiq server..." -sidekiq_server_cmd = "OUTBOXER_ENV=#{outboxer_env} bundle exec sidekiq -r ./config/sidekiq.rb" +sidekiq_server_cmd = "RAILS_ENV=#{outboxer_env} bundle exec sidekiq -r ./config/sidekiq.rb" +puts sidekiq_server_cmd sidekiq_server_process = IO.popen(sidekiq_server_cmd) -puts "Starting outboxer publisher..." outboxer_publisher_cmd = "OUTBOXER_ENV=#{outboxer_env} bin/outboxer_publisher" +puts outboxer_publisher_cmd outboxer_publisher_process = IO.popen(outboxer_publisher_cmd) begin diff --git a/spec/jobs/outboxer_integration/message/publish_job_spec.rb b/spec/jobs/outboxer_integration/message/publish_job_spec.rb index 28aa3d3..f751bc1 100644 --- a/spec/jobs/outboxer_integration/message/publish_job_spec.rb +++ b/spec/jobs/outboxer_integration/message/publish_job_spec.rb @@ -57,7 +57,7 @@ module Message eventable: accountify_organisation, created_at: current_time.utc, body: { - 'organisation' => { 'id' => accountify_organisation.id } }) + 'invoice' => { 'organisation_id' => accountify_organisation.id } }) end before do @@ -86,7 +86,7 @@ module Message eventable: accountify_organisation, created_at: current_time.utc, body: { - 'organisation' => { 'id' => accountify_organisation.id } }) + 'invoice' => { 'organisation_id' => accountify_organisation.id } }) end before do @@ -115,7 +115,7 @@ module Message eventable: accountify_organisation, created_at: current_time.utc, body: { - 'organisation' => { 'id' => accountify_organisation.id } }) + 'invoice' => { 'organisation_id' => accountify_organisation.id } }) end before do @@ -144,7 +144,7 @@ module Message eventable: accountify_organisation, created_at: current_time.utc, body: { - 'organisation' => { 'id' => accountify_organisation.id } }) + 'invoice' => { 'organisation_id' => accountify_organisation.id } }) end before do @@ -173,7 +173,7 @@ module Message eventable: accountify_organisation, created_at: current_time.utc, body: { - 'organisation' => { 'id' => accountify_organisation.id } }) + 'invoice' => { 'organisation_id' => accountify_organisation.id } }) end before do @@ -202,7 +202,7 @@ module Message eventable: accountify_organisation, created_at: current_time.utc, body: { - 'organisation' => { 'id' => accountify_organisation.id } }) + 'invoice' => { 'organisation_id' => accountify_organisation.id } }) end before do