diff --git a/bin/publisher.rb b/bin/publisher.rb deleted file mode 100644 index 3d555121..00000000 --- a/bin/publisher.rb +++ /dev/null @@ -1,28 +0,0 @@ -require 'optparse' -require 'logger' - -options = { concurrency: 5, poll: 1 } - -OptionParser.new do |opts| - opts.banner = "Usage: publisher.rb [options]" - - opts.on("-t", "--concurrency NUMBER", Integer, "Number of worker threads") do |max| - options[:threads_max] = max - end - - opts.on("-p", "--poll INTERVAL", Integer, "Number of seconds to wait when no results or queue is at capacity") do |interval| - options[:poll_interval] = interval - end -end.parse! - -publisher = Outboxer::Publisher.new( - concurrency: options[:concurrency], poll: options[:poll], logger: Logger.new(STDOUT)) - -Signal.trap('INT') { publisher.stop! } - -publisher.publish! do |outboxer_message| - case outboxer_message.outboxer_messageable_type - when 'Event' - EventHandlerWorker.perform_async({ 'id' => outboxer_message.outboxer_messageable_id }) - end -end diff --git a/lib/outboxer/publisher.rb b/lib/outboxer/publisher.rb index 08d5cbf6..52425229 100644 --- a/lib/outboxer/publisher.rb +++ b/lib/outboxer/publisher.rb @@ -154,5 +154,7 @@ def debug_log(message, logger:, threads:, queue:, messages:) logger.debug "#{message} #{summary.to_json}" end + + private_class_method :debug_log end end diff --git a/script/seed_database.rb b/script/seed_database.rb deleted file mode 100755 index e46dd200..00000000 --- a/script/seed_database.rb +++ /dev/null @@ -1,58 +0,0 @@ -#!/usr/bin/env ruby - -require 'bundler/setup' -Bundler.require(:default, :development) - -# psql -d postgres -# CREATE USER outboxer_developer WITH PASSWORD 'outboxer_password'; -# CREATE DATABASE outboxer_development; -# GRANT ALL PRIVILEGES ON DATABASE outboxer_development TO outboxer_developer; - -database_name = ENV.fetch('RAILS_ENV') -database_url = "postgres://outboxer_developer:outboxer_password@localhost/outboxer_#{database_name}" - -ActiveRecord::Base.establish_connection(database_url) - -# ActiveRecord::Base.establish_connection( -# host: "localhost", -# adapter: "postgresql", -# database: "outboxer_development", -# username: "outboxer_developer", -# password: "outboxer_password") - -# existing_tables = %i[outboxer_exceptions outboxer_messages] -# .select { |table| ActiveRecord::Base.connection.table_exists?(table) } -# .each { |existing_table| ActiveRecord::Migration.drop_table(existing_table) } - -require_relative "../generators/outboxer/templates/migrations/create_outboxer_messages" -CreateOutboxerMessages.new.down -CreateOutboxerMessages.new.up - - -require_relative "../generators/outboxer/templates/migrations/create_outboxer_exceptions" -CreateOutboxerExceptions.new.down -CreateOutboxerExceptions.new.up - -# existing_tables = %i[events accounting_invoices] -# .select { |table| ActiveRecord::Base.connection.table_exists?(table) } -# .each { |existing_table| ActiveRecord::Migration.drop_table(existing_table) } - -require_relative "../spec/db/migrate/create_accounting_invoices" -CreateAccountingInvoices.new.down -CreateAccountingInvoices.new.up - -require_relative "../spec/db/migrate/create_events" -CreateEvents.new.down -CreateEvents.new.up - -require_relative "../spec/models/event" -require_relative "../spec/accounting/models/invoice" -require_relative "../spec/accounting/invoice" - -require_relative "../generators/outboxer/templates/workers/event_handler_worker" - -10.times do |_i| - invoice, created_event = Accounting::Invoice.create! - - puts "Invoice##{invoice.id} - #{created_event.type} event #{event.id}" -end diff --git a/sig/outboxer.rbs b/sig/outboxer.rbs deleted file mode 100644 index a96a5705..00000000 --- a/sig/outboxer.rbs +++ /dev/null @@ -1,19 +0,0 @@ -module Outboxer - VERSION: String - - module Publisher - class Args - attr_reader message: untyped - attr_reader logger: Logger - - def initialize: (untyped message, Logger logger) -> void - end - - def self.publish: (?Integer poll, ?Proc[Integer, Integer] backoff) { (Args) -> untyped } -> void - def self.dequeue: ({ backoff: Proc[Integer, Integer] }) -> untyped - def self.published: ({ outboxer_message: untyped, backoff: Proc[Integer, Integer] }) -> void - def self.failed: ({ outboxer_message: untyped, exception: Exception, backoff: Proc[Integer, Integer] }) -> void - def self.retry_on_error: ({ backoff: Proc[Integer, Integer] }) { () -> untyped } -> untyped - def self.stop: () -> void - end -end diff --git a/spec/console.rb b/spec/console.rb index 7fba03f8..a3df5aa3 100755 --- a/spec/console.rb +++ b/spec/console.rb @@ -16,4 +16,4 @@ binding.pry -puts 'hi' +puts 'script finished' diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 481919b0..857d8277 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -34,22 +34,4 @@ # ignore end end - - # config.after(:all) do - # Publisher.disconnect! - # end - - # config.before(:each) do - # ActiveRecord::Base.establish_connection({ - # 'adapter' => 'postgresql', - # 'username' => `whoami`.strip, - # 'database' => 'outboxer_test' - # }) - - # DatabaseCleaner.strategy = :truncation - # end - - # config.after(:each) do - # DatabaseCleaner.clean - # end end diff --git a/spec/tasks/publisher.rake b/spec/tasks/publisher.rake deleted file mode 100644 index 9b596168..00000000 --- a/spec/tasks/publisher.rake +++ /dev/null @@ -1,55 +0,0 @@ -require 'bundler/setup' -Bundler.require(:default, ENV.fetch('RAILS_ENV')) - -namespace :outboxer do - namespace :publisher do - task :publish do - command = "generators/outboxer/templates/bin/outboxer_publisher " \ - "--concurrency=5 "\ - "--poll=1 " \ - "--redis_url=redis://localhost:6379/0 " \ - "--db_config=../../../../config/database.yml" - - system command - end - end -end - -# generators/outboxer/templates/bin/outboxer_publisher.rb --db_config=spec/config/database.yml -# bin/outboxer_publisher # --db_config=config/database.yml - - -# bin/outboxer_publisher \ -# --messageable_type=Models::DomainEvent --worker=workers/domain_event_handler_worker.rb \ -# --messageable_type=Models::Log --worker=workers/log_handler_worker.rb - -# bin/outboxer_publisher \ -# --concurrency=5 -# --poll=1 -# --redis_url=redis://localhost:6379/0 -# --db_config_path=spec/config/database.yml -# --messageable_type=Models::DomainEvent --worker=workers/domain_event_handler_worker.rb \ -# --messageable_type=Models::Log --worker=workers/log_handler_worker.rb - -# 1. run the install generator -# 2. migrate the database -# 3. include outboxable in your models -# 4. add a handler worker -# 5. run the publisher script - -# bin/outboxer_publisher \ -# --concurrency=5 -# --poll=1 -# --redis_url=redis://localhost:6379/0 -# --db_config=spec/config/database.yml -# --messageable_type=Models::DomainEvent --worker=workers/domain_event_handler_worker.rb \ -# --messageable_type=Models::Log --worker=workers/log_handler_worker.rb - - -# ruby generators/outboxer/templates/bin/outboxer_publisher.rb \ -# --concurrency=5 \ -# --poll=1 \ -# --redis_url=redis://localhost:6379/0 \ -# --db_config=spec/config/database.yml \ -# --messageable_type=Models::DomainEvent --worker=workers/domain_event_handler_worker.rb \ -# --messageable_type=Models::Log --worker=workers/log_handler_worker.rb