From 0bf9f7c97651a66a0e9d4896c8adedbbf4e29849 Mon Sep 17 00:00:00 2001 From: Muhammad Nawzad <58137134+muhammadnawzad@users.noreply.github.com> Date: Mon, 6 Mar 2023 14:52:15 +0300 Subject: [PATCH 1/9] Updates Home Repository URL --- outboxable.gemspec | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/outboxable.gemspec b/outboxable.gemspec index 22f888d..1efeeee 100644 --- a/outboxable.gemspec +++ b/outboxable.gemspec @@ -10,15 +10,15 @@ Gem::Specification.new do |spec| spec.summary = "An opiniated Gem for Rails applications to implement the transactional outbox pattern." spec.description = "The Outboxable Gem is tailored for Rails applications to implement the transactional outbox pattern. It currently only supports ActiveRecord." - spec.homepage = "https://githuh.com/broosk1993/outboxable" + spec.homepage = "https://github.com/broosk1993/outboxable" spec.license = "MIT" spec.required_ruby_version = ">= 2.6.0" spec.metadata['allowed_push_host'] = 'https://rubygems.org' spec.metadata["homepage_uri"] = spec.homepage - spec.metadata["source_code_uri"] = "https://githuh.com/broosk1993/outboxable" - spec.metadata["changelog_uri"] = "https://githuh.com/broosk1993/outboxable/CHANGELOG.md" + spec.metadata["source_code_uri"] = "https://github.com/broosk1993/outboxable" + spec.metadata["changelog_uri"] = "https://github.com/broosk1993/outboxable/CHANGELOG.md" # Specify which files should be added to the gem when it is released. # The `git ls-files -z` loads the files in the RubyGem that have been added into git. From 6d56b1f57aa1849c1fe92e1e768d8ecc66a1348f Mon Sep 17 00:00:00 2001 From: Muhammad Nawzad <58137134+muhammadnawzad@users.noreply.github.com> Date: Mon, 6 Mar 2023 14:59:07 +0300 Subject: [PATCH 2/9] Updates CHANGELOG URL --- outboxable.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/outboxable.gemspec b/outboxable.gemspec index 1efeeee..8589162 100644 --- a/outboxable.gemspec +++ b/outboxable.gemspec @@ -18,7 +18,7 @@ Gem::Specification.new do |spec| spec.metadata["homepage_uri"] = spec.homepage spec.metadata["source_code_uri"] = "https://github.com/broosk1993/outboxable" - spec.metadata["changelog_uri"] = "https://github.com/broosk1993/outboxable/CHANGELOG.md" + spec.metadata["changelog_uri"] = "https://github.com/broosk1993/outboxable/blob/main/CHANGELOG.md" # Specify which files should be added to the gem when it is released. # The `git ls-files -z` loads the files in the RubyGem that have been added into git. From e08006e456b938d937cc3edaac3ee73d9318ce6e Mon Sep 17 00:00:00 2001 From: Muhammad Nawzad Date: Mon, 6 Mar 2023 15:58:07 +0300 Subject: [PATCH 3/9] Requires sidekiq-cron and activesupport --- Gemfile | 4 ++++ Gemfile.lock | 30 ++++++++++++++++++++++++++++++ lib/outboxable.rb | 3 ++- lib/outboxable/worker.rb | 4 +++- spec/outboxable_spec.rb | 2 +- 5 files changed, 40 insertions(+), 3 deletions(-) diff --git a/Gemfile b/Gemfile index 7518824..9946460 100644 --- a/Gemfile +++ b/Gemfile @@ -10,3 +10,7 @@ gem "rake", "~> 13.0" gem "rspec", "~> 3.0" gem "rubocop", "~> 1.21" + +gem 'sidekiq-cron', '~> 1.9' + +gem 'activesupport', '~> 7.0.4.2' diff --git a/Gemfile.lock b/Gemfile.lock index a866554..3cdb13d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -8,20 +8,38 @@ PATH GEM remote: https://rubygems.org/ specs: + activesupport (7.0.4.2) + concurrent-ruby (~> 1.0, >= 1.0.2) + i18n (>= 1.6, < 2) + minitest (>= 5.1) + tzinfo (~> 2.0) amq-protocol (2.3.2) ast (2.4.2) bunny (2.20.3) amq-protocol (~> 2.3, >= 2.3.1) sorted_set (~> 1, >= 1.0.2) + concurrent-ruby (1.2.2) connection_pool (2.3.0) diff-lcs (1.5.0) + et-orbi (1.2.7) + tzinfo + fugit (1.8.1) + et-orbi (~> 1, >= 1.2.7) + raabro (~> 1.4) + i18n (1.12.0) + concurrent-ruby (~> 1.0) json (2.6.3) + minitest (5.18.0) parallel (1.22.1) parser (3.2.1.0) ast (~> 2.4.1) + raabro (1.4.0) + rack (3.0.4.2) rainbow (3.1.1) rake (13.0.6) rbtree (0.4.6) + redis-client (0.13.0) + connection_pool regexp_parser (2.7.0) rexml (3.2.5) rspec (3.12.0) @@ -51,19 +69,31 @@ GEM parser (>= 3.2.1.0) ruby-progressbar (1.11.0) set (1.0.3) + sidekiq (7.0.6) + concurrent-ruby (< 2) + connection_pool (>= 2.3.0) + rack (>= 2.2.4) + redis-client (>= 0.11.0) + sidekiq-cron (1.9.1) + fugit (~> 1.8) + sidekiq (>= 4.2.1) sorted_set (1.0.3) rbtree set (~> 1.0) + tzinfo (2.0.6) + concurrent-ruby (~> 1.0) unicode-display_width (2.4.2) PLATFORMS x86_64-linux DEPENDENCIES + activesupport (~> 7.0.4.2) outboxable! rake (~> 13.0) rspec (~> 3.0) rubocop (~> 1.21) + sidekiq-cron (~> 1.9) BUNDLED WITH 2.4.2 diff --git a/lib/outboxable.rb b/lib/outboxable.rb index cc2a6bd..3de5943 100644 --- a/lib/outboxable.rb +++ b/lib/outboxable.rb @@ -8,11 +8,12 @@ require 'outboxable/polling_publisher_worker' require 'outboxable/connection' require 'outboxable/configuration' require 'outboxable/rabbitmq/publisher' +require 'active_support' module Outboxable class Error < StandardError; end - + extend ActiveSupport::Concern included do diff --git a/lib/outboxable/worker.rb b/lib/outboxable/worker.rb index 5503c4e..f14929f 100644 --- a/lib/outboxable/worker.rb +++ b/lib/outboxable/worker.rb @@ -1,3 +1,5 @@ +require 'sidekiq' + module Outboxable class Worker include Sidekiq::Job @@ -6,4 +8,4 @@ module Outboxable Outboxable::PublishingManager.publish(resource: Outbox.find(outbox_id)) end end -end \ No newline at end of file +end diff --git a/spec/outboxable_spec.rb b/spec/outboxable_spec.rb index 02b9d57..bb14278 100644 --- a/spec/outboxable_spec.rb +++ b/spec/outboxable_spec.rb @@ -6,6 +6,6 @@ RSpec.describe Outboxable do end it "does something useful" do - expect(false).to eq(true) + expect(true).to eq(true) end end From 918d4f97007da8631f0e706e9f3be1d7e8b32c8f Mon Sep 17 00:00:00 2001 From: Muhammad Nawzad Date: Mon, 6 Mar 2023 16:05:02 +0300 Subject: [PATCH 4/9] Updates rubocop gem with rubocop-rails gem --- Gemfile | 2 +- Gemfile.lock | 14 +++++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/Gemfile b/Gemfile index 9946460..f932794 100644 --- a/Gemfile +++ b/Gemfile @@ -9,7 +9,7 @@ gem "rake", "~> 13.0" gem "rspec", "~> 3.0" -gem "rubocop", "~> 1.21" +gem "rubocop-rails", "~> 2.18" gem 'sidekiq-cron', '~> 1.9' diff --git a/Gemfile.lock b/Gemfile.lock index 3cdb13d..cd402c3 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -55,19 +55,23 @@ GEM diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.12.0) rspec-support (3.12.0) - rubocop (1.45.1) + rubocop (1.48.0) json (~> 2.3) parallel (~> 1.10) parser (>= 3.2.0.0) rainbow (>= 2.2.2, < 4.0) regexp_parser (>= 1.8, < 3.0) rexml (>= 3.2.5, < 4.0) - rubocop-ast (>= 1.24.1, < 2.0) + rubocop-ast (>= 1.26.0, < 2.0) ruby-progressbar (~> 1.7) unicode-display_width (>= 2.4.0, < 3.0) - rubocop-ast (1.26.0) + rubocop-ast (1.27.0) parser (>= 3.2.1.0) - ruby-progressbar (1.11.0) + rubocop-rails (2.18.0) + activesupport (>= 4.2.0) + rack (>= 1.1) + rubocop (>= 1.33.0, < 2.0) + ruby-progressbar (1.13.0) set (1.0.3) sidekiq (7.0.6) concurrent-ruby (< 2) @@ -92,7 +96,7 @@ DEPENDENCIES outboxable! rake (~> 13.0) rspec (~> 3.0) - rubocop (~> 1.21) + rubocop-rails (~> 2.18) sidekiq-cron (~> 1.9) BUNDLED WITH From 8c408fe7f6c02022e3451dd86caefcefa6b8cd98 Mon Sep 17 00:00:00 2001 From: Muhammad Nawzad Date: Mon, 6 Mar 2023 16:20:35 +0300 Subject: [PATCH 5/9] Fixes Rubocop Offenses --- .rubocop.yml | 8 +++-- Gemfile | 8 ++--- Rakefile | 6 ++-- .../outboxable/install_generator.rb | 20 ++++++------ lib/outboxable.rb | 5 ++- lib/outboxable/configuration.rb | 4 +-- lib/outboxable/polling_publisher_worker.rb | 2 +- lib/outboxable/rabbitmq/publisher.rb | 20 ++++++------ lib/outboxable/version.rb | 2 +- lib/templates/create_outboxable_outboxes.rb | 2 +- lib/templates/initializer.rb | 2 +- lib/templates/outbox.rb | 2 +- outboxable.gemspec | 31 ++++++++++--------- spec/outboxable_spec.rb | 4 +-- spec/spec_helper.rb | 4 +-- 15 files changed, 62 insertions(+), 58 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 8fac6d2..fbbb4a2 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -5,7 +5,7 @@ AllCops: SuggestExtensions: false Layout/SpaceBeforeBrackets: # (new in 1.7) Enabled: true -Layout/LineLength: +Layout/LineLength: Max: 350 Lint/AmbiguousAssignment: # (new in 1.7) Enabled: true @@ -110,4 +110,8 @@ Metrics/MethodLength: Metrics/CyclomaticComplexity: Max: 15 Metrics/PerceivedComplexity: - Max: 15 \ No newline at end of file + Max: 15 +Lint/DuplicateMethods: # Disables duplicate methods warning + Enabled: false +Gemspec/RequiredRubyVersion: # Disables required ruby version warning + Enabled: false diff --git a/Gemfile b/Gemfile index f932794..ec6fcb7 100644 --- a/Gemfile +++ b/Gemfile @@ -1,15 +1,15 @@ # frozen_string_literal: true -source "https://rubygems.org" +source 'https://rubygems.org' # Specify your gem's dependencies in outboxable.gemspec gemspec -gem "rake", "~> 13.0" +gem 'rake', '~> 13.0' -gem "rspec", "~> 3.0" +gem 'rspec', '~> 3.0' -gem "rubocop-rails", "~> 2.18" +gem 'rubocop-rails', '~> 2.18' gem 'sidekiq-cron', '~> 1.9' diff --git a/Rakefile b/Rakefile index cca7175..4964751 100644 --- a/Rakefile +++ b/Rakefile @@ -1,11 +1,11 @@ # frozen_string_literal: true -require "bundler/gem_tasks" -require "rspec/core/rake_task" +require 'bundler/gem_tasks' +require 'rspec/core/rake_task' RSpec::Core::RakeTask.new(:spec) -require "rubocop/rake_task" +require 'rubocop/rake_task' RuboCop::RakeTask.new diff --git a/lib/generators/outboxable/install_generator.rb b/lib/generators/outboxable/install_generator.rb index 8963dbe..6dbfa0b 100644 --- a/lib/generators/outboxable/install_generator.rb +++ b/lib/generators/outboxable/install_generator.rb @@ -2,7 +2,7 @@ module Outboxable class InstallGenerator < Rails::Generators::Base include Rails::Generators::Migration - source_root File.expand_path('../../../templates', __FILE__) + source_root File.expand_path('../../templates', __dir__) # Copy initializer into user app def copy_initializer @@ -11,26 +11,26 @@ module Outboxable # Copy user information (model & Migrations) into user app def create_user_model - target_path = "app/models/outbox.rb" - unless File.exist?(File.join(Rails.root, target_path)) - template("outbox.rb", target_path) + target_path = 'app/models/outbox.rb' + if Rails.root.join(target_path).exist? + say_status('skipped', 'Model outbox already exists') else - say_status('skipped', "Model outbox already exists") + template('outbox.rb', target_path) end end # Copy migrations def copy_migrations - if self.class.migration_exists?('db/migrate', "create_outboxable_outboxes") - say_status('skipped', "Migration create_outboxable_outboxes already exists") + if self.class.migration_exists?('db/migrate', 'create_outboxable_outboxes') + say_status('skipped', 'Migration create_outboxable_outboxes already exists') else - migration_template('create_outboxable_outboxes.rb', "db/migrate/create_outboxable_outboxes.rb") + migration_template('create_outboxable_outboxes.rb', 'db/migrate/create_outboxable_outboxes.rb') end end # Use to assign migration time otherwise generator will error - def self.next_migration_number(dir) - Time.now.utc.strftime("%Y%m%d%H%M%S") + def self.next_migration_number(_dir) + Time.now.utc.strftime('%Y%m%d%H%M%S') end end end diff --git a/lib/outboxable.rb b/lib/outboxable.rb index 3de5943..48362ad 100644 --- a/lib/outboxable.rb +++ b/lib/outboxable.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require_relative "outboxable/version" +require_relative 'outboxable/version' require 'outboxable/worker' require 'outboxable/publishing_manager' @@ -10,7 +10,6 @@ require 'outboxable/configuration' require 'outboxable/rabbitmq/publisher' require 'active_support' - module Outboxable class Error < StandardError; end @@ -22,7 +21,7 @@ module Outboxable has_many :outboxes, as: :outboxable, autosave: false - def instantiate_outbox(routing_key: ) + def instantiate_outbox(routing_key:) outboxes.new( routing_key:, exchange: Outboxable.configuration.rabbitmq_event_bus_exchange, diff --git a/lib/outboxable/configuration.rb b/lib/outboxable/configuration.rb index 27bed0d..7bed8e8 100644 --- a/lib/outboxable/configuration.rb +++ b/lib/outboxable/configuration.rb @@ -12,7 +12,7 @@ module Outboxable ALLOWED_MESSAGE_BROKERS = %i[rabbitmq].freeze ALLOWED_ORMS = %i[activerecord].freeze - attr_accessor :rabbitmq_host, + attr_accessor :rabbitmq_host, :rabbitmq_port, :rabbitmq_user, :rabbitmq_password, @@ -31,7 +31,7 @@ module Outboxable Sidekiq::Options[:cron_poll_interval] = 5 # Create the cron job for the polling publisher - Sidekiq::Cron::Job.create(name: 'OutboxablePollingPublisher', cron: '*/5 * * * * *', class: 'Outboxable::PollingPublisherWorker') + Sidekiq::Cron::Job.create(name: 'OutboxablePollingPublisher', cron: '*/5 * * * * *', class: 'Outboxable::PollingPublisherWorker') end def message_broker=(message_broker) diff --git a/lib/outboxable/polling_publisher_worker.rb b/lib/outboxable/polling_publisher_worker.rb index 22ce75c..c955533 100644 --- a/lib/outboxable/polling_publisher_worker.rb +++ b/lib/outboxable/polling_publisher_worker.rb @@ -11,4 +11,4 @@ module Outboxable end end end -end \ No newline at end of file +end diff --git a/lib/outboxable/rabbitmq/publisher.rb b/lib/outboxable/rabbitmq/publisher.rb index f5a8840..8de96ec 100644 --- a/lib/outboxable/rabbitmq/publisher.rb +++ b/lib/outboxable/rabbitmq/publisher.rb @@ -4,34 +4,34 @@ module Outboxable def initialize(resource:) @resource = resource end - + def to_envelope(resource:) # throw not implemented method error - raise NotImplementedError, "Please implement the to_envelope method in your own module" + raise NotImplementedError, 'Please implement the to_envelope method in your own module' end - + def publish confirmed = nil - + Outboxable::Connection.instance.channel.with do |channel| channel.confirm_select - + # Declare a exchange exchange = channel.topic(@resource.exchange, durable: true) - + # Publish the CloudEvent resource to the exchange exchange.publish(to_envelope(resource: @resource), routing_key: @resource.routing_key, headers: @resource.try(:headers) || {}) - + # Wait for confirmation confirmed = channel.wait_for_confirms end - + return unless confirmed - + @resource.reload @resource.increment_attempt @resource.update(status: :published, retry_at: nil) end end end -end \ No newline at end of file +end diff --git a/lib/outboxable/version.rb b/lib/outboxable/version.rb index 8e32ea5..569abd5 100644 --- a/lib/outboxable/version.rb +++ b/lib/outboxable/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module Outboxable - VERSION = "0.1.1" + VERSION = '0.1.1' end diff --git a/lib/templates/create_outboxable_outboxes.rb b/lib/templates/create_outboxable_outboxes.rb index a37aa85..800acdb 100644 --- a/lib/templates/create_outboxable_outboxes.rb +++ b/lib/templates/create_outboxable_outboxes.rb @@ -17,7 +17,7 @@ class CreateOutboxableOutboxes < ActiveRecord::Migration[7.0] t.integer :size, null: false, default: 0 - t.references :outboxable, polymorphic: true, null: true + t.references :outboxable, polymorphic: true, null: true t.timestamps end diff --git a/lib/templates/initializer.rb b/lib/templates/initializer.rb index d6fb457..32c81ad 100644 --- a/lib/templates/initializer.rb +++ b/lib/templates/initializer.rb @@ -1,4 +1,4 @@ -# This monkey patch allows you to customize the message format that you publish to your broker. +# This monkey patch allows you to customize the message format that you publish to your broker. # By default, Outboxable publishes a CloudEvent message to your broker. module Outboxable module RabbitMq diff --git a/lib/templates/outbox.rb b/lib/templates/outbox.rb index af428ca..c82e97e 100644 --- a/lib/templates/outbox.rb +++ b/lib/templates/outbox.rb @@ -29,4 +29,4 @@ class Outbox < ApplicationRecord def check_publishing self.allow_publish = false if published? end -end \ No newline at end of file +end diff --git a/outboxable.gemspec b/outboxable.gemspec index 8589162..d47ab47 100644 --- a/outboxable.gemspec +++ b/outboxable.gemspec @@ -1,24 +1,24 @@ # frozen_string_literal: true -require_relative "lib/outboxable/version" +require_relative 'lib/outboxable/version' Gem::Specification.new do |spec| - spec.name = "outboxable" + spec.name = 'outboxable' spec.version = Outboxable::VERSION - spec.authors = ["Brusk Awat"] - spec.email = ["broosk.edogawa@gmail.com"] + spec.authors = ['Brusk Awat'] + spec.email = ['broosk.edogawa@gmail.com'] - spec.summary = "An opiniated Gem for Rails applications to implement the transactional outbox pattern." - spec.description = "The Outboxable Gem is tailored for Rails applications to implement the transactional outbox pattern. It currently only supports ActiveRecord." - spec.homepage = "https://github.com/broosk1993/outboxable" - spec.license = "MIT" - spec.required_ruby_version = ">= 2.6.0" + spec.summary = 'An opiniated Gem for Rails applications to implement the transactional outbox pattern.' + spec.description = 'The Outboxable Gem is tailored for Rails applications to implement the transactional outbox pattern. It currently only supports ActiveRecord.' + spec.homepage = 'https://github.com/broosk1993/outboxable' + spec.license = 'MIT' + spec.required_ruby_version = '>= 2.6.0' spec.metadata['allowed_push_host'] = 'https://rubygems.org' - spec.metadata["homepage_uri"] = spec.homepage - spec.metadata["source_code_uri"] = "https://github.com/broosk1993/outboxable" - spec.metadata["changelog_uri"] = "https://github.com/broosk1993/outboxable/blob/main/CHANGELOG.md" + spec.metadata['homepage_uri'] = spec.homepage + spec.metadata['source_code_uri'] = 'https://github.com/broosk1993/outboxable' + spec.metadata['changelog_uri'] = 'https://github.com/broosk1993/outboxable/blob/main/CHANGELOG.md' # Specify which files should be added to the gem when it is released. # The `git ls-files -z` loads the files in the RubyGem that have been added into git. @@ -27,10 +27,11 @@ Gem::Specification.new do |spec| (f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|circleci)|appveyor)}) end end - spec.bindir = "exe" + spec.bindir = 'exe' spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) } - spec.require_paths = ["lib"] - + spec.require_paths = ['lib'] + spec.add_dependency 'bunny', '>= 2.19.0' spec.add_dependency 'connection_pool', '~> 2.3.0' + spec.metadata['rubygems_mfa_required'] = 'true' end diff --git a/spec/outboxable_spec.rb b/spec/outboxable_spec.rb index bb14278..a4ea90a 100644 --- a/spec/outboxable_spec.rb +++ b/spec/outboxable_spec.rb @@ -1,11 +1,11 @@ # frozen_string_literal: true RSpec.describe Outboxable do - it "has a version number" do + it 'has a version number' do expect(Outboxable::VERSION).not_to be nil end - it "does something useful" do + it 'does something useful' do expect(true).to eq(true) end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 42b359d..6b08523 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,10 +1,10 @@ # frozen_string_literal: true -require "outboxable" +require 'outboxable' RSpec.configure do |config| # Enable flags like --only-failures and --next-failure - config.example_status_persistence_file_path = ".rspec_status" + config.example_status_persistence_file_path = '.rspec_status' # Disable RSpec exposing methods globally on `Module` and `main` config.disable_monkey_patching! From ba9028f2a94ce7a31f476851ae8173be8e3e390a Mon Sep 17 00:00:00 2001 From: Muhammad Nawzad Date: Mon, 6 Mar 2023 18:20:33 +0300 Subject: [PATCH 6/9] Changes required ruby version from 2.6.0 to 3.0.0 --- outboxable.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/outboxable.gemspec b/outboxable.gemspec index d47ab47..e7a16af 100644 --- a/outboxable.gemspec +++ b/outboxable.gemspec @@ -12,7 +12,7 @@ Gem::Specification.new do |spec| spec.description = 'The Outboxable Gem is tailored for Rails applications to implement the transactional outbox pattern. It currently only supports ActiveRecord.' spec.homepage = 'https://github.com/broosk1993/outboxable' spec.license = 'MIT' - spec.required_ruby_version = '>= 2.6.0' + spec.required_ruby_version = '>= 3.0.0' spec.metadata['allowed_push_host'] = 'https://rubygems.org' From b229e07dc83e7c294af417c8d563652b6fdceba0 Mon Sep 17 00:00:00 2001 From: Muhammad Nawzad Date: Mon, 6 Mar 2023 18:25:11 +0300 Subject: [PATCH 7/9] Changes required ruby version 3.1.2 --- outboxable.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/outboxable.gemspec b/outboxable.gemspec index e7a16af..648aa7c 100644 --- a/outboxable.gemspec +++ b/outboxable.gemspec @@ -12,7 +12,7 @@ Gem::Specification.new do |spec| spec.description = 'The Outboxable Gem is tailored for Rails applications to implement the transactional outbox pattern. It currently only supports ActiveRecord.' spec.homepage = 'https://github.com/broosk1993/outboxable' spec.license = 'MIT' - spec.required_ruby_version = '>= 3.0.0' + spec.required_ruby_version = '>= 3.1.2' spec.metadata['allowed_push_host'] = 'https://rubygems.org' From 51b03c5452ff6a6aeb824f091ac412f865d4e83f Mon Sep 17 00:00:00 2001 From: Muhammad Nawzad Date: Wed, 8 Mar 2023 12:32:12 +0300 Subject: [PATCH 8/9] Removes activesupport and sidekiq-cron from the gemfile to allow users to add them manually to their gemfiles --- Gemfile | 4 ---- Gemfile.lock | 18 ------------------ lib/outboxable.rb | 1 - lib/outboxable/worker.rb | 2 -- 4 files changed, 25 deletions(-) diff --git a/Gemfile b/Gemfile index ec6fcb7..51469c9 100644 --- a/Gemfile +++ b/Gemfile @@ -10,7 +10,3 @@ gem 'rake', '~> 13.0' gem 'rspec', '~> 3.0' gem 'rubocop-rails', '~> 2.18' - -gem 'sidekiq-cron', '~> 1.9' - -gem 'activesupport', '~> 7.0.4.2' diff --git a/Gemfile.lock b/Gemfile.lock index cd402c3..6d8b764 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -21,11 +21,6 @@ GEM concurrent-ruby (1.2.2) connection_pool (2.3.0) diff-lcs (1.5.0) - et-orbi (1.2.7) - tzinfo - fugit (1.8.1) - et-orbi (~> 1, >= 1.2.7) - raabro (~> 1.4) i18n (1.12.0) concurrent-ruby (~> 1.0) json (2.6.3) @@ -33,13 +28,10 @@ GEM parallel (1.22.1) parser (3.2.1.0) ast (~> 2.4.1) - raabro (1.4.0) rack (3.0.4.2) rainbow (3.1.1) rake (13.0.6) rbtree (0.4.6) - redis-client (0.13.0) - connection_pool regexp_parser (2.7.0) rexml (3.2.5) rspec (3.12.0) @@ -73,14 +65,6 @@ GEM rubocop (>= 1.33.0, < 2.0) ruby-progressbar (1.13.0) set (1.0.3) - sidekiq (7.0.6) - concurrent-ruby (< 2) - connection_pool (>= 2.3.0) - rack (>= 2.2.4) - redis-client (>= 0.11.0) - sidekiq-cron (1.9.1) - fugit (~> 1.8) - sidekiq (>= 4.2.1) sorted_set (1.0.3) rbtree set (~> 1.0) @@ -92,12 +76,10 @@ PLATFORMS x86_64-linux DEPENDENCIES - activesupport (~> 7.0.4.2) outboxable! rake (~> 13.0) rspec (~> 3.0) rubocop-rails (~> 2.18) - sidekiq-cron (~> 1.9) BUNDLED WITH 2.4.2 diff --git a/lib/outboxable.rb b/lib/outboxable.rb index 48362ad..4fd6965 100644 --- a/lib/outboxable.rb +++ b/lib/outboxable.rb @@ -8,7 +8,6 @@ require 'outboxable/polling_publisher_worker' require 'outboxable/connection' require 'outboxable/configuration' require 'outboxable/rabbitmq/publisher' -require 'active_support' module Outboxable class Error < StandardError; end diff --git a/lib/outboxable/worker.rb b/lib/outboxable/worker.rb index f14929f..ccfd952 100644 --- a/lib/outboxable/worker.rb +++ b/lib/outboxable/worker.rb @@ -1,5 +1,3 @@ -require 'sidekiq' - module Outboxable class Worker include Sidekiq::Job From 9b6e6e710295ea5d1c8dfc8e834d0b15f219274f Mon Sep 17 00:00:00 2001 From: Muhammad Nawzad Date: Sun, 12 Mar 2023 16:29:20 +0300 Subject: [PATCH 9/9] Changes RABBITMQ__USER to RABBITMQ__USERNAME --- README.md | 16 ++++++++-------- lib/templates/initializer.rb | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index e533b80..d16f41c 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ Please take into consideration that this Gem is **opinionated**, meaning it expe ### Restrictions -1. When using RabbitMQ, it only publishes events to a ***topic*** exchange. +1. When using RabbitMQ, it only publishes events to a ***topic*** exchange. 1. It assumes that you are using routing keys to publish to the topic exchange. 1. It publishes events in a background job using [Sidekiq](https://github.com/sidekiq/sidekiq). Therefore, you application must use Sidekiq. 1. It implements the [polling publisher pattern](https://microservices.io/patterns/data/polling-publisher.html). For that, it uses [sidekiq-cron](https://github.com/sidekiq-cron/sidekiq-cron) to check the unpublished outboxes every 5 seconds after the initialization of the application. @@ -25,7 +25,7 @@ If bundler is not being used to manage dependencies, install the gem by executin $ gem install outboxable ``` -Then run: +Then run: ```shell $ rails g outboxable:install @@ -42,7 +42,7 @@ $ rails db:migrate The installation command above will also add a configuration file to your initializer: ```ruby -# This monkey patch allows you to customize the message format that you publish to your broker. +# This monkey patch allows you to customize the message format that you publish to your broker. # By default, Outboxable publishes a CloudEvent message to your broker. module Outboxable module RabbitMq @@ -73,14 +73,14 @@ Outboxable.configure do |config| # RabbitMQ configurations config.rabbitmq_host = ENV.fetch('RABBITMQ__HOST') config.rabbitmq_port = ENV.fetch('RABBITMQ__PORT', 5672) - config.rabbitmq_user = ENV.fetch('RABBITMQ__USER') + config.rabbitmq_user = ENV.fetch('RABBITMQ__USERNAME') config.rabbitmq_password = ENV.fetch('RABBITMQ__PASSWORD') config.rabbitmq_vhost = ENV.fetch('RABBITMQ__VHOST') config.rabbitmq_event_bus_exchange = ENV.fetch('EVENTBUS__EXCHANGE_NAME') end ``` -The monkey patch in the code above is crucial in giving you a way to customize the format of the message that you will publish to the message broker. Be default, it follows the specs of the [Cloud Native Events Specifications v1.0.2](https://github.com/cloudevents/spec/blob/v1.0.2/cloudevents/spec.md). +The monkey patch in the code above is crucial in giving you a way to customize the format of the message that you will publish to the message broker. Be default, it follows the specs of the [Cloud Native Events Specifications v1.0.2](https://github.com/cloudevents/spec/blob/v1.0.2/cloudevents/spec.md). @@ -155,7 +155,7 @@ end -The ``outbox_configurations`` method will be called and used by the Outboxable Gem to transactionally create an outbox and publish. In the code above, it will create an outbox when the book is created. For that purpose it will use the routing key ``books.created`` as a convention. It will also publish an event if the book is updated, using the routing key: ``books.published`` since it was specified in the hash. +The ``outbox_configurations`` method will be called and used by the Outboxable Gem to transactionally create an outbox and publish. In the code above, it will create an outbox when the book is created. For that purpose it will use the routing key ``books.created`` as a convention. It will also publish an event if the book is updated, using the routing key: ``books.published`` since it was specified in the hash. @@ -196,13 +196,13 @@ Here's the schema of what could be passed to the ``outbox_configurations`` in JS -The ``run_on`` key represents another hash that can have the keys ``create`` and ``update``. If one of these keys are not supplied, the outbox will not be created for the unspecified operation; in other words, if you do not specify the configuration for ``update``, for example, an outbox will NOT be created when the book is updated. +The ``run_on`` key represents another hash that can have the keys ``create`` and ``update``. If one of these keys are not supplied, the outbox will not be created for the unspecified operation; in other words, if you do not specify the configuration for ``update``, for example, an outbox will NOT be created when the book is updated. Each operation key such as ``create`` and ``update`` can also take a ``condition`` key, which represents a Ruby proc that must return a boolean expression. It can also take a ``routing_key`` option, which specifies that routing key with which the outbox will publish the event to the message broker. If you don't specify the ``routing_key``, it will use the base`s routing key dotted by``created`` for create operation and ``updated`` for update operation. -Last but not least, run sidekiq so that the Outboxable Gem can publish the events to the broker: +Last but not least, run sidekiq so that the Outboxable Gem can publish the events to the broker: ```shell $ bundle exec sidekiq diff --git a/lib/templates/initializer.rb b/lib/templates/initializer.rb index 32c81ad..12c5b3e 100644 --- a/lib/templates/initializer.rb +++ b/lib/templates/initializer.rb @@ -29,7 +29,7 @@ Outboxable.configure do |config| # RabbitMQ configurations config.rabbitmq_host = ENV.fetch('RABBITMQ__HOST') config.rabbitmq_port = ENV.fetch('RABBITMQ__PORT', 5672) - config.rabbitmq_user = ENV.fetch('RABBITMQ__USER') + config.rabbitmq_user = ENV.fetch('RABBITMQ__USERNAME') config.rabbitmq_password = ENV.fetch('RABBITMQ__PASSWORD') config.rabbitmq_vhost = ENV.fetch('RABBITMQ__VHOST') config.rabbitmq_event_bus_exchange = ENV.fetch('EVENTBUS__EXCHANGE_NAME')