Instance checks and wipe on complete

This commit is contained in:
SimplifiedPrivacy 2026-10-09 14:33:19 -04:00
parent 430696b480
commit 4aa6e2fb8b

View file

@ -20,7 +20,6 @@ MAX_FAILED_CONNECTIONS = 8
class CheckPaidTimer: class CheckPaidTimer:
_instance = None # CLASS VARIABLE - survives across __init__ calls _instance = None # CLASS VARIABLE - survives across __init__ calls
@ -48,9 +47,17 @@ class CheckPaidTimer:
self.failed_connections = 0 self.failed_connections = 0
self.total_attempts = 0 self.total_attempts = 0
logger.info("Check Paid Timer initialized. Starting polling..") logger.info("Check Paid Timer initialized.")
self.start_polling() # self.start_polling()
@classmethod
def get_instance(cls, *args, **kwargs):
if cls._instance is None:
cls(*args, **kwargs)
return cls._instance
def start_polling(self): def start_polling(self):
logger.info("Starting polling") logger.info("Starting polling")
"""If there is a billing code to check if it's paid, it begins the checks.""" """If there is a billing code to check if it's paid, it begins the checks."""
@ -65,8 +72,9 @@ class CheckPaidTimer:
self.poll_thread.start() self.poll_thread.start()
def stop_polling(self): def stop_polling(self):
"""Stops checking if paid""" """Stops checking if paid and wipes the instance"""
self.is_running = False self.is_running = False # stop checking if paid
CheckPaidTimer._instance = None # wipes instance
logger.info("Polling stopped") logger.info("Polling stopped")
def _poll_loop(self): def _poll_loop(self):
@ -101,6 +109,9 @@ class CheckPaidTimer:
print("PAID! Stopping timer") print("PAID! Stopping timer")
self.stop_polling() self.stop_polling()
# Reset instance:
CheckPaidTimer._instance = None
# SAVE: # SAVE:
marked = mark_as_paid(profile_id=self.profile_id) marked = mark_as_paid(profile_id=self.profile_id)
if not marked.valid: if not marked.valid:
@ -122,11 +133,13 @@ class CheckPaidTimer:
elif result.error_type == ResultError.INVALID_INPUT: elif result.error_type == ResultError.INVALID_INPUT:
print("immediately stop, the billing code or other input is invalid") print("immediately stop, the billing code or other input is invalid")
self.stop_polling() self.stop_polling()
CheckPaidTimer._instance = None # Reset instance
self.view_callback(paid=False, stopped=True, message=result.message) self.view_callback(paid=False, stopped=True, message=result.message)
# connection error (timed out). Not related to payment status: # connection error (timed out). Not related to payment status:
elif self.failed_connections > MAX_FAILED_CONNECTIONS: elif self.failed_connections > MAX_FAILED_CONNECTIONS:
self.stop_polling() self.stop_polling()
CheckPaidTimer._instance = None # Reset instance
message = f"Your network connection timed out after {self.failed_connections} failed attempts" message = f"Your network connection timed out after {self.failed_connections} failed attempts"
self.view_callback(paid=False, stopped=True, message=message) self.view_callback(paid=False, stopped=True, message=message)
@ -141,5 +154,6 @@ class CheckPaidTimer:
print(f"result.error_type is {result.error_type}") print(f"result.error_type is {result.error_type}")
print(f"result.message is {result.error_type}") print(f"result.message is {result.error_type}")
self.stop_polling() self.stop_polling()
CheckPaidTimer._instance = None
self.view_callback(paid=False, stopped=True, message=result.message) self.view_callback(paid=False, stopped=True, message=result.message)