From 64ed7c9e34a82c356ee0066f893a3db13347d5ac Mon Sep 17 00:00:00 2001 From: bedrock-adam Date: Sat, 11 Oct 2025 18:01:23 +1100 Subject: [PATCH 1/4] commit changes --- lib/outboxer/message.rb | 8 ++++---- spec/bin/outboxer_publisher_spec.rb | 16 ++++------------ spec/lib/outboxer/message/publish_spec.rb | 4 ++-- .../outboxer/publisher/publish_message_spec.rb | 4 ++-- 4 files changed, 12 insertions(+), 20 deletions(-) diff --git a/lib/outboxer/message.rb b/lib/outboxer/message.rb index b3aa2501..c2f11b3a 100644 --- a/lib/outboxer/message.rb +++ b/lib/outboxer/message.rb @@ -258,15 +258,15 @@ def published(id:, time: ::Time) ActiveRecord::Base.connection_pool.with_connection do ActiveRecord::Base.transaction do - message = Models::Message.lock.find_by!(id: id) + message = Models::Message.includes(exceptions: :frames).lock.find_by!(id: id) if message.status != Models::Message::Status::PUBLISHING raise Error, "Status must be publishing" end - message.update!( - status: Status::PUBLISHED, - updated_at: current_utc_time, published_at: current_utc_time) + message.exceptions.each { |exception| exception.frames.each(&:delete) } + message.exceptions.delete_all + message.delete partition = calculate_partition(id: message.id) diff --git a/spec/bin/outboxer_publisher_spec.rb b/spec/bin/outboxer_publisher_spec.rb index 6eff1600..e5fb0098 100644 --- a/spec/bin/outboxer_publisher_spec.rb +++ b/spec/bin/outboxer_publisher_spec.rb @@ -13,26 +13,18 @@ it "publishes message" do attempt = 1 + published_count = Outboxer::Message.count_by_status["published"] - was_published = Outboxer::Message - .list(status: :published) - .fetch(:messages) - .any? { |published_message| published_message[:id] == message[:id] } - - while (attempt <= max_attempts) && !was_published + while (attempt <= max_attempts) && published_count.zero? warn "Outboxer message not published yet. Retrying (#{attempt}/#{max_attempts})..." sleep delay attempt += 1 - - was_published = Outboxer::Message - .list(status: :published) - .fetch(:messages) - .any? { |published_message| published_message[:id] == message[:id] } + published_count = Outboxer::Message.count_by_status["published"] end Process.kill("TERM", publisher_pid) Process.wait(publisher_pid) - expect(was_published).to be true + expect(published_count).to be > 0 end end diff --git a/spec/lib/outboxer/message/publish_spec.rb b/spec/lib/outboxer/message/publish_spec.rb index 57c40759..66074ef3 100644 --- a/spec/lib/outboxer/message/publish_spec.rb +++ b/spec/lib/outboxer/message/publish_spec.rb @@ -28,8 +28,8 @@ module Outboxer messageable_type: queued_message.messageable_type, messageable_id: queued_message.messageable_id }) - expect(queued_message.reload.status) - .to eq(Models::Message::Status::PUBLISHED) + + expect(Models::Message.published.count).to eql(0) end it "returns { id: ... } and marks as failed on StandardError" do diff --git a/spec/lib/outboxer/publisher/publish_message_spec.rb b/spec/lib/outboxer/publisher/publish_message_spec.rb index 75ad0aa2..d96683b7 100644 --- a/spec/lib/outboxer/publisher/publish_message_spec.rb +++ b/spec/lib/outboxer/publisher/publish_message_spec.rb @@ -192,7 +192,7 @@ module Outboxer ::Process.kill("TERM", ::Process.pid) end - expect(Models::Message.published.count).to eq(1) + expect(Models::Message.published.count).to eq(0) end end @@ -213,7 +213,7 @@ module Outboxer ::Process.kill("TERM", ::Process.pid) end - expect(Models::Message.published.count).to eq(1) + expect(Models::Message.published.count).to eq(0) end end From 6df500861e6207bd8be1e14cbbd51b1126a7806f Mon Sep 17 00:00:00 2001 From: bedrock-adam Date: Sat, 11 Oct 2025 18:24:23 +1100 Subject: [PATCH 2/4] fix e2e tests --- quickstart_e2e_tests.sh | 29 ++++++++--------------------- 1 file changed, 8 insertions(+), 21 deletions(-) diff --git a/quickstart_e2e_tests.sh b/quickstart_e2e_tests.sh index c146b0c5..393dcbad 100755 --- a/quickstart_e2e_tests.sh +++ b/quickstart_e2e_tests.sh @@ -42,7 +42,7 @@ bundle exec rails new . \ bundle install bundle exec rails db:create -echo 'gem "outboxer", git: "https://github.com/fast-programmer/outboxer.git", branch: "master"' \ +echo 'gem "outboxer", git: "https://github.com/fast-programmer/outboxer.git", branch: "refactor/delete_published_outboxer_messages"' \ >> Gemfile bundle install bundle exec rails generate outboxer:install @@ -76,32 +76,19 @@ attempt = 1 max_attempts = 10 delay = 1 -messageable_was_published = false +published_count = Outboxer::Message.count_by_status["published"] -published_messages = Outboxer::Message.list(status: :published)[:messages] - -messageable_was_published = published_messages.any? do |published_message| - published_message[:messageable_type] == event.class.name && - published_message[:messageable_id] == event.id.to_s -end - -while (attempt <= max_attempts) && !messageable_was_published - warn "Outboxer message not published yet. Retrying (#{attempt}/#{max_attempts})..." - sleep delay - attempt += 1 - - published_messages = Outboxer::Message.list(status: :published)[:messages] - - messageable_was_published = published_messages.any? do |published_message| - published_message[:messageable_type] == event.class.name && - published_message[:messageable_id] == event.id.to_s - end +while (attempt <= max_attempts) && published_count.zero? + warn "Outboxer not published yet (#{attempt}/#{max_attempts})..." + sleep delay + attempt += 1 + published_count = Outboxer::Message.count_by_status["published"] end Process.kill("TERM", publisher_pid) Process.wait(publisher_pid) -exit(messageable_was_published ? 0 : 1) +exit(published_count.positive? ? 0 : 1) RUBY # TARGET_RUBY_VERSION=3.2.2 TARGET_RAILS_VERSION=7.1.5.1 TARGET_DATABASE_ADAPTER=postgresql ./quickstart_e2e_tests.sh From 6ac4c56d3cbd2c53ef2893f2788e4cba75f05ed8 Mon Sep 17 00:00:00 2001 From: bedrock-adam Date: Sat, 11 Oct 2025 18:38:08 +1100 Subject: [PATCH 3/4] update install generator --- generators/install_generator.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/generators/install_generator.rb b/generators/install_generator.rb index b84d3606..8b22af86 100644 --- a/generators/install_generator.rb +++ b/generators/install_generator.rb @@ -21,6 +21,14 @@ def copy_migrations "db/migrate/create_outboxer_messages.rb", "db/migrate/create_outboxer_messages.rb") + migration_template( + "db/migrate/create_outboxer_message_counts.rb", + "db/migrate/create_outboxer_message_counts.rb") + + migration_template( + "db/migrate/create_outboxer_message_totals.rb", + "db/migrate/create_outboxer_message_totals.rb") + migration_template( "db/migrate/create_outboxer_exceptions.rb", "db/migrate/create_outboxer_exceptions.rb") From 069bc0f6722da8167b4ee4dae5f37c91f258195d Mon Sep 17 00:00:00 2001 From: bedrock-adam Date: Sat, 11 Oct 2025 18:44:58 +1100 Subject: [PATCH 4/4] remove published list --- lib/outboxer/message.rb | 2 +- lib/outboxer/web/views/layout.erb | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/outboxer/message.rb b/lib/outboxer/message.rb index c2f11b3a..07ced9c5 100644 --- a/lib/outboxer/message.rb +++ b/lib/outboxer/message.rb @@ -500,7 +500,7 @@ def requeue(id:, publisher_id: nil, publisher_name: nil, end end - LIST_STATUS_OPTIONS = [nil, :queued, :publishing, :published, :failed] + LIST_STATUS_OPTIONS = [nil, :queued, :publishing, :failed] LIST_STATUS_DEFAULT = nil LIST_SORT_OPTIONS = [:id, :status, :messageable, :queued_at, :updated_at, :publisher_name] diff --git a/lib/outboxer/web/views/layout.erb b/lib/outboxer/web/views/layout.erb index 3ccf4805..48d6923f 100644 --- a/lib/outboxer/web/views/layout.erb +++ b/lib/outboxer/web/views/layout.erb @@ -65,7 +65,6 @@ <% statuses = [ { name: 'Queued', key: 'queued' }, { name: 'Publishing', key: 'publishing' }, - { name: 'Published', key: 'published' }, { name: 'Failed', key: 'failed' } ] %>