@@ -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
@@ -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)
@@ -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,