From c3579ccce30c94d864e7c821f9790d1f4c28d52d Mon Sep 17 00:00:00 2001 From: Stephen Paul Weber Date: Tue, 31 Jan 2023 14:56:37 -0500 Subject: [PATCH] Only try to catch up possible renewals if expired less than 3 months --- sgx_jmp.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/sgx_jmp.rb b/sgx_jmp.rb index 78f498c..cefb94d 100644 --- a/sgx_jmp.rb +++ b/sgx_jmp.rb @@ -202,7 +202,10 @@ def catchup_notify_possible_renewal(db) db.query(<<~SQL).each do |c| SELECT customer_id FROM customer_plans INNER JOIN balances USING (customer_id) - WHERE expires_at < LOCALTIMESTAMP AND balance >= 5 + WHERE + expires_at < LOCALTIMESTAMP + AND expires_at >= LOCALTIMESTAMP - INTERVAL '3 months' + AND balance >= 5 SQL db.query("SELECT pg_notify('possible_renewal', $1)", c.values) end -- 2.45.2