Skip to content

Commit

Permalink
Merge branch 'feat/add-box-id' into 'master'
Browse files Browse the repository at this point in the history
DEX-2262 feat: implement box_id

See merge request nstmrt/rubygems/outbox!91
  • Loading branch information
bibendi committed May 2, 2024
2 parents 32bd8d8 + 301c554 commit 0e6b4a8
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 15 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 5 additions & 1 deletion app/models/sbmt/outbox/base_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 5 additions & 4 deletions app/models/sbmt/outbox/base_item_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand Down Expand Up @@ -109,7 +110,7 @@ def transports

private

attr_accessor :box_name
attr_accessor :box_id, :box_name

def options
@options ||= lookup_config || {}
Expand All @@ -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?
Expand Down
2 changes: 1 addition & 1 deletion lib/sbmt/outbox/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected].7/dist/assets/index.js"
c.cdn_url = "https://cdn.jsdelivr.net/npm/[email protected].8/dist/assets/index.js"
end
c.process_items = ActiveSupport::OrderedOptions.new.tap do |c|
c.general_timeout = 120
Expand Down
2 changes: 1 addition & 1 deletion lib/sbmt/outbox/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

module Sbmt
module Outbox
VERSION = "6.3.0"
VERSION = "6.3.1"
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions spec/models/sbmt/outbox/inbox_item_config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions spec/models/sbmt/outbox/outbox_item_config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 0e6b4a8

Please sign in to comment.