~singpolyma/sgx-jmp

3b0ae3c9387d3be41b30bd6dd4552ff0a841d8ed — Stephen Paul Weber 7 months ago 45d76a6
Need repo too during bill plan command
3 files changed, 9 insertions(+), 8 deletions(-)

M lib/db_notification.rb
M lib/dummy_command.rb
M sgx_jmp.rb
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))