From d2d3d3c7703559096ddfe53ddef621655ad9bd6f Mon Sep 17 00:00:00 2001 From: Stephen Paul Weber Date: Tue, 11 May 2021 09:13:12 -0500 Subject: [PATCH] Only notify expired users once a week --- bin/billing_monthly_cronjob | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/bin/billing_monthly_cronjob b/bin/billing_monthly_cronjob index e088306..cf36660 100755 --- a/bin/billing_monthly_cronjob +++ b/bin/billing_monthly_cronjob @@ -128,10 +128,14 @@ class ExpiredCustomer @plan = plan end + def customer_id + @row["customer_id"] + end + def try_renew(db, stats) @plan.renew( db, - @row["customer_id"], + customer_id, @row["expires_at"] ) @@ -140,8 +144,19 @@ class ExpiredCustomer end class WithLowBalance < ExpiredCustomer + ONE_WEEK = 60 * 60 * 24 * 7 + def try_renew(_, stats) - jid = REDIS.get("jmp_customer_jid-#{@row['customer_id']}") + stats.add(:not_renewed, 1) + return if REDIS.exists?("jmp_customer_low_balance-#{customer_id}") + REDIS.set("jmp_customer_low_balance-#{customer_id}", Time.now, ex: ONE_WEEK) + send_notification + end + + protected + + def send_notification + jid = REDIS.get("jmp_customer_jid-#{customer_id}") tel = REDIS.lindex("catapult_cred-#{jid}", 3) BlatherNotify.say( CONFIG[:notify_using][:target].call(jid), @@ -149,12 +164,8 @@ class ExpiredCustomer jid, format_renewal_notification(tel) ) ) - - stats.add(:not_renewed, 1) end - protected - def format_renewal_notification(tel) <<~NOTIFY Failed to renew account for #{tel}, -- 2.38.5