From 27a02de2e8b1fdbf587f69ae9df0a8197ba1050d Mon Sep 17 00:00:00 2001 From: Stephen Paul Weber Date: Wed, 11 Aug 2021 12:58:01 -0500 Subject: [PATCH] Bring in line with the key from billing_monthly_cronjob --- lib/expiring_lock.rb | 2 +- lib/low_balance.rb | 3 ++- test/test_low_balance.rb | 10 +++++----- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/lib/expiring_lock.rb b/lib/expiring_lock.rb index 3f43d5aea06d9a821cdfe915758be11ae2c58c73..42c967a71dc67d9e0811a6155a39573b11cf8e1d 100644 --- a/lib/expiring_lock.rb +++ b/lib/expiring_lock.rb @@ -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 diff --git a/lib/low_balance.rb b/lib/low_balance.rb index 4f9f73eed617482e2b3c7e7c05099987af6c4251..e58ab5fc733c8ef208be529eb91b02a3bd572821 100644 --- a/lib/low_balance.rb +++ b/lib/low_balance.rb @@ -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) diff --git a/test/test_low_balance.rb b/test/test_low_balance.rb index e023f202926ab427243a6b97dcde8ed0ad299dcd..0ceeed9d4d57b3e161d7d314686438cc0a5a8a0a 100644 --- a/test/test_low_balance.rb +++ b/test/test_low_balance.rb @@ -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,