From 301c5546b92832cd098933336a9ac006224d3a9b Mon Sep 17 00:00:00 2001 From: Misha Merkushin Date: Wed, 1 May 2024 16:47:08 +0300 Subject: [PATCH] feat: implement box_id --- CHANGELOG.md | 8 ++++++++ .../sbmt/outbox/api/inbox_classes_controller.rb | 2 +- .../sbmt/outbox/api/outbox_classes_controller.rb | 2 +- app/models/sbmt/outbox/base_item.rb | 6 +++++- app/models/sbmt/outbox/base_item_config.rb | 9 +++++---- lib/sbmt/outbox/engine.rb | 2 +- lib/sbmt/outbox/version.rb | 2 +- .../sbmt/outbox/api/inbox_classes_controller_spec.rb | 2 +- .../sbmt/outbox/api/outbox_classes_controller_spec.rb | 2 +- spec/models/sbmt/outbox/inbox_item_config_spec.rb | 4 ++-- spec/models/sbmt/outbox/outbox_item_config_spec.rb | 4 ++-- 11 files changed, 28 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6a97f1b..a3e20f1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,8 +7,16 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] - yyyy-mm-dd +## [6.3.1] - 2024-05-01 + +### Added + +- Add box_id to make it url safe for use in the API. + ## [6.3.0] - 2024-04-18 +### Added + - Add support for [Outbox UI](https://github.com/SberMarket-Tech/sbmt-outbox-ui) - Add ability to pause poller v2 diff --git a/app/controllers/sbmt/outbox/api/inbox_classes_controller.rb b/app/controllers/sbmt/outbox/api/inbox_classes_controller.rb index d30b6f1..f211ee4 100644 --- a/app/controllers/sbmt/outbox/api/inbox_classes_controller.rb +++ b/app/controllers/sbmt/outbox/api/inbox_classes_controller.rb @@ -6,7 +6,7 @@ module Api class InboxClassesController < BaseController def index render_list(Sbmt::Outbox.inbox_item_classes.map do |item| - Sbmt::Outbox::Api::InboxClass.find_or_initialize(item.box_name) + Sbmt::Outbox::Api::InboxClass.find_or_initialize(item.box_id) end) end diff --git a/app/controllers/sbmt/outbox/api/outbox_classes_controller.rb b/app/controllers/sbmt/outbox/api/outbox_classes_controller.rb index 7d5eaf4..95cf462 100644 --- a/app/controllers/sbmt/outbox/api/outbox_classes_controller.rb +++ b/app/controllers/sbmt/outbox/api/outbox_classes_controller.rb @@ -6,7 +6,7 @@ module Api class OutboxClassesController < BaseController def index render_list(Sbmt::Outbox.outbox_item_classes.map do |item| - Api::OutboxClass.find_or_initialize(item.box_name) + Api::OutboxClass.find_or_initialize(item.box_id) end) end diff --git a/app/models/sbmt/outbox/base_item.rb b/app/models/sbmt/outbox/base_item.rb index 5708b07..6a9ae63 100644 --- a/app/models/sbmt/outbox/base_item.rb +++ b/app/models/sbmt/outbox/base_item.rb @@ -16,8 +16,12 @@ def box_name @box_name ||= name.underscore end + def box_id + @box_id ||= name.underscore.tr("/", "-").dasherize + end + def config - @config ||= lookup_config.new(box_name) + @config ||= lookup_config.new(box_id: box_id, box_name: box_name) end def calc_bucket_partitions(count) diff --git a/app/models/sbmt/outbox/base_item_config.rb b/app/models/sbmt/outbox/base_item_config.rb index 8a9b5b3..0db85c2 100644 --- a/app/models/sbmt/outbox/base_item_config.rb +++ b/app/models/sbmt/outbox/base_item_config.rb @@ -8,7 +8,8 @@ class BaseItemConfig delegate :yaml_config, :memory_store, to: "Sbmt::Outbox" - def initialize(box_name) + def initialize(box_id:, box_name:) + self.box_id = box_id self.box_name = box_name validate! @@ -109,7 +110,7 @@ def transports private - attr_accessor :box_name + attr_accessor :box_id, :box_name def options @options ||= lookup_config || {} @@ -129,8 +130,8 @@ def polling_auto_disabled? end def polling_enabled_for?(api_model) - record = memory_store.fetch("sbmt/outbox/outbox_item_config/#{box_name}", expires_in: 10) do - api_model.find(box_name) + record = memory_store.fetch("sbmt/outbox/outbox_item_config/#{box_id}", expires_in: 10) do + api_model.find(box_id) end if record.nil? diff --git a/lib/sbmt/outbox/engine.rb b/lib/sbmt/outbox/engine.rb index 5fdee50..0fad663 100644 --- a/lib/sbmt/outbox/engine.rb +++ b/lib/sbmt/outbox/engine.rb @@ -22,7 +22,7 @@ class Engine < Rails::Engine c.ui = ActiveSupport::OrderedOptions.new.tap do |c| c.serve_local = false c.local_endpoint = "http://localhost:5173" - c.cdn_url = "https://cdn.jsdelivr.net/npm/sbmt-outbox-ui@0.0.7/dist/assets/index.js" + c.cdn_url = "https://cdn.jsdelivr.net/npm/sbmt-outbox-ui@0.0.8/dist/assets/index.js" end c.process_items = ActiveSupport::OrderedOptions.new.tap do |c| c.general_timeout = 120 diff --git a/lib/sbmt/outbox/version.rb b/lib/sbmt/outbox/version.rb index 3cb41dd..38e631b 100644 --- a/lib/sbmt/outbox/version.rb +++ b/lib/sbmt/outbox/version.rb @@ -2,6 +2,6 @@ module Sbmt module Outbox - VERSION = "6.3.0" + VERSION = "6.3.1" end end diff --git a/spec/controllers/sbmt/outbox/api/inbox_classes_controller_spec.rb b/spec/controllers/sbmt/outbox/api/inbox_classes_controller_spec.rb index fc84a0b..d22afa2 100644 --- a/spec/controllers/sbmt/outbox/api/inbox_classes_controller_spec.rb +++ b/spec/controllers/sbmt/outbox/api/inbox_classes_controller_spec.rb @@ -12,7 +12,7 @@ expect(response).to be_successful data = response.parsed_body expect(data).not_to be_empty - expect(data.pluck("id")).to include("inbox_item") + expect(data.pluck("id")).to include("inbox-item") end end diff --git a/spec/controllers/sbmt/outbox/api/outbox_classes_controller_spec.rb b/spec/controllers/sbmt/outbox/api/outbox_classes_controller_spec.rb index 8dc4efe..ae1c889 100644 --- a/spec/controllers/sbmt/outbox/api/outbox_classes_controller_spec.rb +++ b/spec/controllers/sbmt/outbox/api/outbox_classes_controller_spec.rb @@ -12,7 +12,7 @@ expect(response).to be_successful data = response.parsed_body expect(data).not_to be_empty - expect(data.pluck("id")).to include("outbox_item", "combined/outbox_item") + expect(data.pluck("id")).to include("outbox-item", "combined-outbox-item") end end diff --git a/spec/models/sbmt/outbox/inbox_item_config_spec.rb b/spec/models/sbmt/outbox/inbox_item_config_spec.rb index 27150c7..719358c 100644 --- a/spec/models/sbmt/outbox/inbox_item_config_spec.rb +++ b/spec/models/sbmt/outbox/inbox_item_config_spec.rb @@ -8,7 +8,7 @@ end context "when polling is disabled" do - before { Sbmt::Outbox::Api::InboxClass.new(id: InboxItem.box_name, polling_enabled: false).save } + before { Sbmt::Outbox::Api::InboxClass.new(id: InboxItem.box_id, polling_enabled: false).save } it { expect(config.polling_enabled?).to be false } end @@ -19,7 +19,7 @@ it { expect(config.polling_enabled?).to be false } context "when polling is enabled on the box" do - before { Sbmt::Outbox::Api::InboxClass.new(id: InboxItem.box_name, polling_enabled: true).save } + before { Sbmt::Outbox::Api::InboxClass.new(id: InboxItem.box_id, polling_enabled: true).save } it { expect(config.polling_enabled?).to be true } end diff --git a/spec/models/sbmt/outbox/outbox_item_config_spec.rb b/spec/models/sbmt/outbox/outbox_item_config_spec.rb index 0483b53..57e4433 100644 --- a/spec/models/sbmt/outbox/outbox_item_config_spec.rb +++ b/spec/models/sbmt/outbox/outbox_item_config_spec.rb @@ -8,7 +8,7 @@ end context "when polling is disabled" do - before { Sbmt::Outbox::Api::OutboxClass.new(id: OutboxItem.box_name, polling_enabled: false).save } + before { Sbmt::Outbox::Api::OutboxClass.new(id: OutboxItem.box_id, polling_enabled: false).save } it { expect(config.polling_enabled?).to be false } end @@ -19,7 +19,7 @@ it { expect(config.polling_enabled?).to be false } context "when polling is enabled on the box" do - before { Sbmt::Outbox::Api::OutboxClass.new(id: OutboxItem.box_name, polling_enabled: true).save } + before { Sbmt::Outbox::Api::OutboxClass.new(id: OutboxItem.box_id, polling_enabled: true).save } it { expect(config.polling_enabled?).to be true } end