Skip to content

Commit

Permalink
rename env -> environment
Browse files Browse the repository at this point in the history
  • Loading branch information
bedrock-adam committed Jan 1, 2025
1 parent df9a41c commit 7b038c7
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 34 deletions.
4 changes: 2 additions & 2 deletions bin/console
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down
4 changes: 2 additions & 2 deletions bin/outboxer_load
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lib/outboxer/database.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions lib/outboxer/publisher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lib/outboxer/web.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions spec/lib/outboxer/database/connect_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions spec/lib/outboxer/publisher/publish_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -97,7 +97,7 @@ module Outboxer

before do
Publisher.publish(
env: env,
environment: environment,
buffer: buffer,
poll: poll,
tick: tick,
Expand Down Expand Up @@ -143,7 +143,7 @@ module Outboxer

before do
Publisher.publish(
env: env,
environment: environment,
buffer: buffer,
poll: poll,
tick: tick,
Expand Down Expand Up @@ -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,
Expand All @@ -221,7 +221,7 @@ module Outboxer
.once

Publisher.publish(
env: env,
environment: environment,
buffer: buffer,
poll: poll,
tick: tick,
Expand Down
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 13 additions & 13 deletions tasks/database.rake
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,26 @@ 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'])
ActiveRecord::Base.connection.disconnect!
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'])
ActiveRecord::Base.connection.disconnect!
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"
Expand Down Expand Up @@ -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!
Expand All @@ -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

0 comments on commit 7b038c7

Please sign in to comment.