~singpolyma/sgx-jmp

27a02de2e8b1fdbf587f69ae9df0a8197ba1050d — Stephen Paul Weber 1 year, 1 month ago 9347725
Bring in line with the key from billing_monthly_cronjob
3 files changed, 8 insertions(+), 7 deletions(-)

M lib/expiring_lock.rb
M lib/low_balance.rb
M test/test_low_balance.rb
M lib/expiring_lock.rb => lib/expiring_lock.rb +1 -1
@@ 11,7 11,7 @@ class ExpiringLock
			next els&.call if exists == 1

			EMPromise.resolve(yield).then do |rval|
				REDIS.setex(@name, @expiry, "").then { rval }
				REDIS.setex(@name, @expiry, Time.now).then { rval }
			end
		end
	end

M lib/low_balance.rb => lib/low_balance.rb +2 -1
@@ 6,7 6,8 @@ require_relative "transaction"
class LowBalance
	def self.for(customer)
		ExpiringLock.new(
			"jmp_low_balance_notify-#{customer.customer_id}"
			"jmp_customer_low_balance-#{customer.customer_id}",
			expiry: 60 * 60 * 24 * 7
		).with(-> { Locked.new }) do
			customer.auto_top_up_amount.then do |auto_top_up_amount|
				for_auto_top_up_amount(customer, auto_top_up_amount)

M test/test_low_balance.rb => test/test_low_balance.rb +5 -5
@@ 12,7 12,7 @@ class LowBalanceTest < Minitest::Test
		ExpiringLock::REDIS.expect(
			:exists,
			EMPromise.resolve(1),
			["jmp_low_balance_notify-test"]
			["jmp_customer_low_balance-test"]
		)
		assert_kind_of LowBalance::Locked, LowBalance.for(customer).sync
	end


@@ 22,7 22,7 @@ class LowBalanceTest < Minitest::Test
		ExpiringLock::REDIS.expect(
			:exists,
			EMPromise.resolve(0),
			["jmp_low_balance_notify-test"]
			["jmp_customer_low_balance-test"]
		)
		CustomerPlan::REDIS.expect(
			:get,


@@ 37,7 37,7 @@ class LowBalanceTest < Minitest::Test
		ExpiringLock::REDIS.expect(
			:setex,
			EMPromise.resolve(nil),
			["jmp_low_balance_notify-test", 60 * 60 * 24, ""]
			["jmp_customer_low_balance-test", 60 * 60 * 24 * 7, Time]
		)
		assert_kind_of(
			LowBalance,


@@ 51,7 51,7 @@ class LowBalanceTest < Minitest::Test
		ExpiringLock::REDIS.expect(
			:exists,
			EMPromise.resolve(0),
			["jmp_low_balance_notify-test"]
			["jmp_customer_low_balance-test"]
		)
		CustomerPlan::REDIS.expect(
			:get,


@@ 61,7 61,7 @@ class LowBalanceTest < Minitest::Test
		ExpiringLock::REDIS.expect(
			:setex,
			EMPromise.resolve(nil),
			["jmp_low_balance_notify-test", 60 * 60 * 24, ""]
			["jmp_customer_low_balance-test", 60 * 60 * 24 * 7, Time]
		)
		assert_kind_of(
			LowBalance::AutoTopUp,