Only try to catch up possible renewals if expired less than 3 months

Stephen Paul Weber created

Change summary

sgx_jmp.rb | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)

Detailed changes

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