M lib/db_notification.rb => lib/db_notification.rb +2 -2
@@ 3,12 3,12 @@
require_relative "dummy_command"
module DbNotification
- def self.for(notify, customer)
+ def self.for(notify, customer, customer_repo)
case notify[:relname]
when "low_balance"
LowBalance.for(customer).then { |lb| lb.method(:notify!) }
when "possible_renewal"
- Command.execution = DummyCommand.new(customer)
+ Command.execution = DummyCommand.new(customer, customer_repo)
BillPlanCommand.for(customer)
else
raise "Unknown notification: #{notify[:relname]}"
M lib/dummy_command.rb => lib/dummy_command.rb +3 -2
@@ 1,10 1,11 @@
# frozen_string_literal: true
class DummyCommand
- attr_reader :customer
+ attr_reader :customer, :customer_repo
- def initialize(customer)
+ def initialize(customer, customer_repo)
@customer = customer
+ @customer_repo = customer_repo
end
def reply(*); end
M sgx_jmp.rb => sgx_jmp.rb +4 -4
@@ 196,10 196,10 @@ end
def poll_for_notify(db)
db.wait_for_notify_defer.then { |notify|
- CustomerRepo
- .new(sgx_repo: Bwmsgsv2Repo.new)
- .find(notify[:extra])
- .then { |customer| DbNotification.for(notify, customer) }
+ repo = CustomerRepo.new(sgx_repo: Bwmsgsv2Repo.new)
+ repo.find(notify[:extra]).then do |customer|
+ DbNotification.for(notify, customer, repo)
+ end
}.then(&:call).then {
poll_for_notify(db)
}.catch(&method(:panic))