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