From b656750212c5f5ce543f9ed92a354693c0538475 Mon Sep 17 00:00:00 2001 From: bedrock-adam Date: Sun, 15 Dec 2024 14:32:23 +1100 Subject: [PATCH 1/8] add outboxer --- .github/workflows/ci.yml | 10 +++++++ .../message/publish_job.rb | 12 ++++----- script/accountify/invoice/test_lifecycle.rb | 27 ++++++++++++------- .../accountify/invoice/test_lifecycle_spec.rb | 2 +- .../message/publish_job_spec.rb | 12 ++++----- 5 files changed, 41 insertions(+), 22 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 943b111..ce18575 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/script/accountify/invoice/test_lifecycle.rb b/script/accountify/invoice/test_lifecycle.rb index 0baaf43..93e5e70 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,9 +69,15 @@ 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) +outboxer_env = ENV['OUTBOXER_ENV'] || ENV['RAILS_ENV'] || 'development' + +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) + +outboxer_publisher_cmd = "OUTBOXER_ENV=#{outboxer_env} bin/outboxer_publisher" +puts outboxer_publisher_cmd +outboxer_publisher_process = IO.popen(outboxer_publisher_cmd) begin invoice_status_summary = nil @@ -93,13 +99,16 @@ 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_publisher_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 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 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 From 33ed076055e0fd9fe016f407c734277b25a755a5 Mon Sep 17 00:00:00 2001 From: bedrock-adam Date: Sun, 15 Dec 2024 14:46:47 +1100 Subject: [PATCH 2/8] try different command --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ce18575..3988279 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -73,7 +73,7 @@ jobs: 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 + { sed '$d' lib/event.rb; printf "\n # callbacks\n\n after_create do |event|\n Outboxer::Message.queue(messageable: event)\n end\nend\n"; } > lib/event.tmp && mv lib/event.tmp lib/event.rb - name: Run tests run: bundle exec rspec From efdee16037cbc6651317217aa307b9ca64f6ecd0 Mon Sep 17 00:00:00 2001 From: bedrock-adam Date: Sun, 15 Dec 2024 15:02:14 +1100 Subject: [PATCH 3/8] test off branch --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3988279..790824c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -67,7 +67,7 @@ jobs: - name: add Outboxer run: | - echo "gem 'outboxer', git: 'https://github.com/fast-programmer/outboxer.git', branch: 'master'" >> Gemfile + echo "gem 'outboxer', git: 'https://github.com/fast-programmer/outboxer.git', branch: 'feature/add_outboxer_integration_message_publish_job'" >> Gemfile bundle install bin/rails g outboxer:schema bin/rake db:migrate From e46fd17e5ba259c81828c0bc0ebe5603ae4228b7 Mon Sep 17 00:00:00 2001 From: bedrock-adam Date: Sun, 15 Dec 2024 15:08:06 +1100 Subject: [PATCH 4/8] switch to master branch --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 790824c..3988279 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -67,7 +67,7 @@ jobs: - name: add Outboxer run: | - echo "gem 'outboxer', git: 'https://github.com/fast-programmer/outboxer.git', branch: 'feature/add_outboxer_integration_message_publish_job'" >> Gemfile + 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 From 1825958ed1a331c478c98e65f3c6f9d943b7dc27 Mon Sep 17 00:00:00 2001 From: bedrock-adam Date: Mon, 27 Jan 2025 16:14:12 +1100 Subject: [PATCH 5/8] fix build --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3988279..5d16257 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -69,7 +69,7 @@ jobs: run: | echo "gem 'outboxer', git: 'https://github.com/fast-programmer/outboxer.git', branch: 'master'" >> Gemfile bundle install - bin/rails g outboxer:schema + bin/rails g outboxer:install bin/rake db:migrate bin/rake outboxer:db:seed bin/rails g outboxer:sidekiq_publisher From 174ddfe87c1b2c0a76b130ea24336061bf031a43 Mon Sep 17 00:00:00 2001 From: bedrock-adam Date: Mon, 27 Jan 2025 16:18:22 +1100 Subject: [PATCH 6/8] remove seeds in pipeline to fix --- .github/workflows/ci.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5d16257..77f99c3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -71,7 +71,6 @@ jobs: bundle install bin/rails g outboxer:install bin/rake db:migrate - bin/rake outboxer:db:seed bin/rails g outboxer:sidekiq_publisher { sed '$d' lib/event.rb; printf "\n # callbacks\n\n after_create do |event|\n Outboxer::Message.queue(messageable: event)\n end\nend\n"; } > lib/event.tmp && mv lib/event.tmp lib/event.rb From f4e15f5f99655ab1a5f43fd5985a42fefbde7c6e Mon Sep 17 00:00:00 2001 From: bedrock-adam Date: Mon, 27 Jan 2025 16:28:00 +1100 Subject: [PATCH 7/8] fix build --- .github/workflows/ci.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 77f99c3..63c0950 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -71,7 +71,6 @@ jobs: bundle install bin/rails g outboxer:install bin/rake db:migrate - bin/rails g outboxer:sidekiq_publisher { sed '$d' lib/event.rb; printf "\n # callbacks\n\n after_create do |event|\n Outboxer::Message.queue(messageable: event)\n end\nend\n"; } > lib/event.tmp && mv lib/event.tmp lib/event.rb - name: Run tests From 1dfc36c6852381f1176cf9d70224bf4a49936349 Mon Sep 17 00:00:00 2001 From: bedrock-adam Date: Mon, 27 Jan 2025 16:49:43 +1100 Subject: [PATCH 8/8] add lib --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 63c0950..05a20c4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -71,6 +71,7 @@ jobs: bundle install bin/rails g outboxer:install bin/rake db:migrate + mkdir lib { sed '$d' lib/event.rb; printf "\n # callbacks\n\n after_create do |event|\n Outboxer::Message.queue(messageable: event)\n end\nend\n"; } > lib/event.tmp && mv lib/event.tmp lib/event.rb - name: Run tests