From 3b0ae3c9387d3be41b30bd6dd4552ff0a841d8ed Mon Sep 17 00:00:00 2001 From: Stephen Paul Weber Date: Tue, 26 Apr 2022 10:17:04 -0500 Subject: [PATCH] Need repo too during bill plan command --- lib/db_notification.rb | 4 ++-- lib/dummy_command.rb | 5 +++-- sgx_jmp.rb | 8 ++++---- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/lib/db_notification.rb b/lib/db_notification.rb index d9b7f1f7545976920904568b8eea1c1db5c767c9..bbfe331ba356e6bffcec41da09990e656de83731 100644 --- a/lib/db_notification.rb +++ b/lib/db_notification.rb @@ -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]}" diff --git a/lib/dummy_command.rb b/lib/dummy_command.rb index 7df14ceb5c3adff3109fb0cfa41547fb9f0a54b1..09cced2236ea4bd0fd8fa7232177e35cc08204c4 100644 --- a/lib/dummy_command.rb +++ b/lib/dummy_command.rb @@ -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 diff --git a/sgx_jmp.rb b/sgx_jmp.rb index ad80b29feae13641e7ae35852c9e3c4c7f3e45d2..f6ab1058c4617f9ae2cecfa86fa119c9d75108e7 100644 --- a/sgx_jmp.rb +++ b/sgx_jmp.rb @@ -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))