Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions db/migrate/create_outboxer_counters.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
class CreateOutboxerCounters < ActiveRecord::Migration[6.1]
def up
create_table :outboxer_counters do |t|
t.string :hostname, limit: 255
t.integer :process_id
t.integer :thread_id

t.integer :publisher_id

t.integer :queued_count, null: false
t.integer :publishing_count, null: false
t.integer :published_count, null: false
t.integer :failed_count, null: false

t.timestamps
end

add_index :outboxer_counters, [:hostname, :process_id, :thread_id],
unique: true, name: "idx_outboxer_counters_identity"
end

def down
drop_table :outboxer_counters if table_exists?(:outboxer_counters)
end
end
25 changes: 0 additions & 25 deletions db/migrate/create_outboxer_thread_counters.rb

This file was deleted.

2 changes: 1 addition & 1 deletion lib/outboxer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
require_relative "outboxer/models/message"
require_relative "outboxer/models/message_count"
require_relative "outboxer/models/message_total"
require_relative "outboxer/models/thread_counter"
require_relative "outboxer/models/counter"

require_relative "outboxer/models/publisher"
require_relative "outboxer/models/signal"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Outboxer
module Models
class ThreadCounter < ::ActiveRecord::Base
self.table_name = "outboxer_thread_counters"
class Counter < ::ActiveRecord::Base
self.table_name = "outboxer_counters"

def self.insert_or_increment_by(hostname: Socket.gethostname,
process_id: Process.pid,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module Outboxer
module Models
RSpec.describe ThreadCounter, type: :model do
RSpec.describe Counter, type: :model do
describe ".insert_or_increment_by" do
let(:hostname) { "test-host" }
let(:process_id) { 12_345 }
Expand All @@ -11,16 +11,16 @@ module Models

it "inserts a new row successfully" do
expect do
ThreadCounter.insert_or_increment_by(
Counter.insert_or_increment_by(
hostname: hostname,
process_id: process_id,
thread_id: thread_id,
queued_count: 1,
time: now
)
end.to change(ThreadCounter, :count).by(1)
end.to change(Counter, :count).by(1)

row = ThreadCounter.find_by(
row = Counter.find_by(
hostname: hostname,
process_id: process_id,
thread_id: thread_id
Expand All @@ -31,21 +31,21 @@ module Models
end

it "increments existing counts if called again" do
ThreadCounter.insert_or_increment_by(
Counter.insert_or_increment_by(
hostname: hostname,
process_id: process_id,
thread_id: thread_id,
queued_count: 1
)

ThreadCounter.insert_or_increment_by(
Counter.insert_or_increment_by(
hostname: hostname,
process_id: process_id,
thread_id: thread_id,
queued_count: 2
)

row = ThreadCounter.find_by(
row = Counter.find_by(
hostname: hostname,
process_id: process_id,
thread_id: thread_id
Expand All @@ -55,7 +55,7 @@ module Models
end

it "updates multiple counters atomically" do
ThreadCounter.insert_or_increment_by(
Counter.insert_or_increment_by(
hostname: hostname,
process_id: process_id,
thread_id: thread_id,
Expand All @@ -64,7 +64,7 @@ module Models
failed_count: 3
)

row = ThreadCounter.find_by(
row = Counter.find_by(
hostname: hostname,
process_id: process_id,
thread_id: thread_id
Expand All @@ -77,15 +77,15 @@ module Models

it "does not create duplicate rows on repeated calls" do
3.times do
ThreadCounter.insert_or_increment_by(
Counter.insert_or_increment_by(
hostname: hostname,
process_id: process_id,
thread_id: thread_id,
queued_count: 1
)
end

count = ThreadCounter.where(
count = Counter.where(
hostname: hostname,
process_id: process_id,
thread_id: thread_id
Expand Down
4 changes: 2 additions & 2 deletions tasks/database.rake
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ namespace :outboxer do
db_config = Outboxer::Database.config(environment: environment, pool: 1)
ActiveRecord::Base.establish_connection(db_config)

require_relative "../db/migrate/create_outboxer_thread_counters"
CreateOutboxerThreadCounters.new.up
require_relative "../db/migrate/create_outboxer_counters"
CreateOutboxerCounters.new.up

require_relative "../db/migrate/create_outboxer_messages"
CreateOutboxerMessages.new.up
Expand Down