From 7b038c7cdcd35278b4a791ec7290416b4c465b2b Mon Sep 17 00:00:00 2001 From: bedrock-adam Date: Wed, 1 Jan 2025 22:30:02 +1100 Subject: [PATCH] rename env -> environment --- bin/console | 4 ++-- bin/outboxer_load | 4 ++-- lib/outboxer/database.rb | 4 ++-- lib/outboxer/publisher.rb | 5 ++-- lib/outboxer/web.rb | 4 ++-- spec/lib/outboxer/database/connect_spec.rb | 4 ++-- spec/lib/outboxer/publisher/publish_spec.rb | 16 ++++++------- spec/spec_helper.rb | 2 +- tasks/database.rake | 26 ++++++++++----------- 9 files changed, 35 insertions(+), 34 deletions(-) diff --git a/bin/console b/bin/console index 6bbe2978..f3c2c1a0 100755 --- a/bin/console +++ b/bin/console @@ -10,8 +10,8 @@ Dir.glob(File.join(__dir__, '../app/models/**/*.rb')).each do |file| require_relative file end -env = ENV['OUTBOXER_ENV'] || 'development' -config = Outboxer::Database.config(env: env, pool: 1) +environment = ENV['RAILS_ENV'] || 'development' +config = Outboxer::Database.config(environment: environment, pool: 1) Outboxer::Database.connect(config: config) Sidekiq.configure_client do |config| diff --git a/bin/outboxer_load b/bin/outboxer_load index 455e914e..ef38e9be 100755 --- a/bin/outboxer_load +++ b/bin/outboxer_load @@ -12,8 +12,8 @@ if max_messages_count <= 0 exit(1) end -db_config = Outboxer::Database.config( - env: ENV.fetch('OUTBOXER_ENV', 'development'), pool: 1) +environment = ENV.fetch('RAILS_ENV', 'development') +db_config = Outboxer::Database.config(environment: environment, pool: 1) Outboxer::Database.connect(config: db_config) Signal.trap('INT') do diff --git a/lib/outboxer/database.rb b/lib/outboxer/database.rb index 28798e6c..9941ed74 100644 --- a/lib/outboxer/database.rb +++ b/lib/outboxer/database.rb @@ -5,10 +5,10 @@ module Outboxer module Database extend self - def config(env:, pool:, path: ::File.expand_path('config/database.yml', ::Dir.pwd)) + def config(environment:, pool:, path: ::File.expand_path('config/database.yml', ::Dir.pwd)) db_config_content = File.read(path) db_config_erb_result = ERB.new(db_config_content).result - db_config = YAML.safe_load(db_config_erb_result, aliases: true)[env] + db_config = YAML.safe_load(db_config_erb_result, aliases: true)[environment] db_config['pool'] = pool db_config end diff --git a/lib/outboxer/publisher.rb b/lib/outboxer/publisher.rb index 663986d8..2562cf8e 100644 --- a/lib/outboxer/publisher.rb +++ b/lib/outboxer/publisher.rb @@ -368,7 +368,7 @@ def handle_signal(id:, name:, logger:, process:) def publish( name: "#{::Socket.gethostname}:#{::Process.pid}", - env: ::ENV.fetch('RAILS_ENV', 'development'), + environment: ::ENV.fetch('RAILS_ENV', 'development'), db_config_path: ::File.expand_path('config/database.yml', ::Dir.pwd), buffer: 100, concurrency: 1, tick: 0.1, poll: 5.0, heartbeat: 5.0, @@ -382,7 +382,8 @@ def publish( logger.info "Outboxer v#{Outboxer::VERSION} running in ruby #{RUBY_VERSION} "\ "(#{RUBY_RELEASE_DATE} revision #{RUBY_REVISION[0, 10]}) [#{RUBY_PLATFORM}]" - db_config = database.config(env: env, pool: concurrency + 2, path: db_config_path) + db_config = database.config( + environment: environment, pool: concurrency + 2, path: db_config_path) database.connect(config: db_config, logger: logger) Settings.create diff --git a/lib/outboxer/web.rb b/lib/outboxer/web.rb index 7accf2e1..5dd37395 100755 --- a/lib/outboxer/web.rb +++ b/lib/outboxer/web.rb @@ -31,9 +31,9 @@ require 'uri' require 'rack/flash' -env = ENV['OUTBOXER_ENV'] || 'development' +environment = ENV['RAILS_ENV'] || 'development' -config = Outboxer::Database.config(env: env, pool: 5) +config = Outboxer::Database.config(environment: environment, pool: 5) Outboxer::Database.connect(config: config) module Outboxer diff --git a/spec/lib/outboxer/database/connect_spec.rb b/spec/lib/outboxer/database/connect_spec.rb index c1bee59d..8898257d 100644 --- a/spec/lib/outboxer/database/connect_spec.rb +++ b/spec/lib/outboxer/database/connect_spec.rb @@ -6,12 +6,12 @@ module Outboxer before(:each) { Database.disconnect(logger: nil) } after(:all) do - config = Database.config(env: 'test', pool: 20) + config = Database.config(environment: 'test', pool: 20) Database.connect(config: config, logger: nil) end context 'when db config valid' do - let(:config) { Database.config(env: 'test', pool: 20) } + let(:config) { Database.config(environment: 'test', pool: 20) } it 'establishes a connection without errors' do expect do diff --git a/spec/lib/outboxer/publisher/publish_spec.rb b/spec/lib/outboxer/publisher/publish_spec.rb index 670c64fa..7fc15835 100644 --- a/spec/lib/outboxer/publisher/publish_spec.rb +++ b/spec/lib/outboxer/publisher/publish_spec.rb @@ -3,7 +3,7 @@ module Outboxer RSpec.describe Publisher do describe '.publish' do - let(:env) { 'test' } + let(:environment) { 'test' } let(:buffer) { 1 } let(:poll) { 1 } let(:tick) { 0.1 } @@ -21,7 +21,7 @@ module Outboxer it 'dumps stack trace' do publish_thread = Thread.new do Outboxer::Publisher.publish( - env: env, + environment: environment, buffer: buffer, poll: poll, tick: tick, @@ -46,7 +46,7 @@ module Outboxer it 'stops and resumes the publishing process correctly' do publish_thread = Thread.new do Outboxer::Publisher.publish( - env: env, + environment: environment, buffer: buffer, poll: poll, tick: tick, @@ -71,7 +71,7 @@ module Outboxer context 'when message published successfully' do it 'sets the message to published' do Publisher.publish( - env: env, + environment: environment, buffer: buffer, poll: poll, tick: tick, @@ -97,7 +97,7 @@ module Outboxer before do Publisher.publish( - env: env, + environment: environment, buffer: buffer, poll: poll, tick: tick, @@ -143,7 +143,7 @@ module Outboxer before do Publisher.publish( - env: env, + environment: environment, buffer: buffer, poll: poll, tick: tick, @@ -201,7 +201,7 @@ module Outboxer expect(logger).to receive(:error).with(include('StandardError: queue error')).once Publisher.publish( - env: env, + environment: environment, buffer: buffer, poll: poll, tick: tick, @@ -221,7 +221,7 @@ module Outboxer .once Publisher.publish( - env: env, + environment: environment, buffer: buffer, poll: poll, tick: tick, diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 1f83afe6..ca268810 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -20,7 +20,7 @@ config.include FactoryBot::Syntax::Methods config.before(:all) do - db_config = Outboxer::Database.config(env: 'test', pool: 2) + db_config = Outboxer::Database.config(environment: 'test', pool: 2) Outboxer::Database.connect(config: db_config, logger: nil) DatabaseCleaner.strategy = :truncation diff --git a/tasks/database.rake b/tasks/database.rake index c89a1415..3d932f2c 100644 --- a/tasks/database.rake +++ b/tasks/database.rake @@ -6,8 +6,8 @@ require 'pry-byebug' namespace :outboxer do namespace :db do task :drop do - env = ENV['OUTBOXER_ENV'] || 'development' - db_config = Outboxer::Database.config(env: env, pool: 1) + environment = ENV['RAILS_ENV'] || 'development' + db_config = Outboxer::Database.config(environment: environment, pool: 1) ActiveRecord::Base.establish_connection(db_config.merge('database' => 'postgres')) ActiveRecord::Base.connection.drop_database(db_config['database']) @@ -15,8 +15,8 @@ namespace :outboxer do end task :create do - env = ENV['OUTBOXER_ENV'] || 'development' - db_config = Outboxer::Database.config(env: env, pool: 1) + environment = ENV['RAILS_ENV'] || 'development' + db_config = Outboxer::Database.config(environment: environment, pool: 1) ActiveRecord::Base.establish_connection(db_config.merge('database' => 'postgres')) ActiveRecord::Base.connection.create_database(db_config['database']) @@ -24,8 +24,8 @@ namespace :outboxer do end task :migrate do - env = ENV['OUTBOXER_ENV'] || 'development' - db_config = Outboxer::Database.config(env: env, pool: 1) + environment = ENV['RAILS_ENV'] || 'development' + db_config = Outboxer::Database.config(environment: environment, pool: 1) ActiveRecord::Base.establish_connection(db_config) require_relative "../db/migrate/create_outboxer_integration_tests" @@ -56,8 +56,8 @@ namespace :outboxer do end task :seed do - env = ENV['OUTBOXER_ENV'] || 'development' - db_config = Outboxer::Database.config(env: env, pool: 1) + environment = ENV['RAILS_ENV'] || 'development' + db_config = Outboxer::Database.config(environment: environment, pool: 1) ActiveRecord::Base.establish_connection(db_config) ActiveRecord::Base.connection.disconnect! @@ -69,8 +69,8 @@ namespace :outboxer do end end -# OUTBOXER_ENV=development bin/rake outboxer:db:drop -# OUTBOXER_ENV=development bin/rake outboxer:db:create -# OUTBOXER_ENV=development bin/rake outboxer:db:migrate -# OUTBOXER_ENV=development bin/rake outboxer:db:seed -# OUTBOXER_ENV=development bin/rake outboxer:db:reset +# RAILS_ENV=development bin/rake outboxer:db:drop +# RAILS_ENV=development bin/rake outboxer:db:create +# RAILS_ENV=development bin/rake outboxer:db:migrate +# RAILS_ENV=development bin/rake outboxer:db:seed +# RAILS_ENV=development bin/rake outboxer:db:reset