Skip to content

Commit

Permalink
add Settings.create (#213)
Browse files Browse the repository at this point in the history
  • Loading branch information
bedrock-adam authored Dec 21, 2024
1 parent 949ab80 commit 2c015d0
Show file tree
Hide file tree
Showing 12 changed files with 46 additions and 29 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ module OutboxerIntegration
class PublishJob
include Sidekiq::Job

def perform_async(args)
# TODO: handle published message here
def perform(args)
# TODO: handle message here
end
end
end
Expand Down
11 changes: 0 additions & 11 deletions db/seeds.rb

This file was deleted.

1 change: 1 addition & 0 deletions lib/outboxer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

require_relative "outboxer/logger"
require_relative "outboxer/database"
require_relative "outboxer/settings"
require_relative "outboxer/message"
require_relative "outboxer/messages"
require_relative "outboxer/publisher"
Expand Down
2 changes: 1 addition & 1 deletion lib/outboxer/models/setting.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module Models
class Setting < ActiveRecord::Base
self.table_name = 'outboxer_settings'

validates :name, presence: true, uniqueness: true
validates :name, presence: true
validates :value, presence: true
end
end
Expand Down
2 changes: 2 additions & 0 deletions lib/outboxer/publisher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,8 @@ def publish(
db_config = database.config(env: env, pool: concurrency + 2, path: db_config_path)
database.connect(config: db_config, logger: logger)

Settings.create

queue = Queue.new

publisher = create(
Expand Down
11 changes: 0 additions & 11 deletions lib/outboxer/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,5 @@ class Railtie < Rails::Railtie
require_relative '../../generators/sidekiq_publisher_generator'
require_relative '../../generators/publisher_generator'
end

rake_tasks do
namespace :outboxer do
namespace :db do
desc "Load outboxer's seed data"
task seed: :environment do
load File.expand_path('../../db/seeds.rb', __dir__)
end
end
end
end
end
end
21 changes: 21 additions & 0 deletions lib/outboxer/settings.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module Outboxer
module Settings
extend self

def create
ActiveRecord::Base.connection_pool.with_connection do
begin
Outboxer::Models::Setting.create!(name: 'messages.published.count.historic', value: '0')
rescue ActiveRecord::RecordNotUnique
# no op as record already exists
end

begin
Outboxer::Models::Setting.create!(name: 'messages.failed.count.historic', value: '0')
rescue ActiveRecord::RecordNotUnique
# no op as record already exists
end
end
end
end
end
4 changes: 4 additions & 0 deletions lib/outboxer/web.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ class Web < Sinatra::Base
set :public_folder, File.expand_path('../web/public', __FILE__)
set :show_exceptions, false

configure do
Settings.create
end

helpers do
def outboxer_path(path)
"#{request.script_name}#{path}"
Expand Down
1 change: 0 additions & 1 deletion outboxer.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ Gem::Specification.new do |spec|

spec_files = Dir.chdir(__dir__) do
[
'db/seeds.rb',
'db/migrate/**/*',
'generators/**/*',
'LICENCE.txt',
Expand Down
14 changes: 14 additions & 0 deletions spec/lib/outboxer/settings/create_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
require 'spec_helper'

module Outboxer
RSpec.describe Settings, type: :module do
describe '.create' do
it 'creates setting' do
Settings.create

expect(Models::Setting.find_by(name: 'messages.published.count.historic').value).to eq('0')
expect(Models::Setting.find_by(name: 'messages.failed.count.historic').value).to eq('0')
end
end
end
end
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@
# ignore
end

load File.join(File.dirname(__FILE__), '../db/seeds.rb')
Outboxer::Settings.create
end
end
2 changes: 0 additions & 2 deletions tasks/database.rake
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ namespace :outboxer do
db_config = Outboxer::Database.config(env: env, pool: 1)
ActiveRecord::Base.establish_connection(db_config)

require_relative "../db/seeds"

ActiveRecord::Base.connection.disconnect!
end

Expand Down

0 comments on commit 2c015d0

Please sign in to comment.