Skip to content

Commit 26e7ed1

Browse files
committed
Testing some stuff out to see if it actually worked correctly or not..
1 parent 7927564 commit 26e7ed1

2 files changed

Lines changed: 68 additions & 8 deletions

File tree

‎ASFScan.py‎

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from lib.logger import logger
1515

1616
# Version information
17-
VERSION = "2.1.1-dev"
17+
VERSION = "2.1.1-dev2"
1818

1919
# Load environment variables from .env file
2020
load_dotenv()
@@ -78,6 +78,8 @@ def process_comment(comment, subreddit_name):
7878
license_commands = extract_license_commands(comment.body)
7979
new_licenses = [license for license in license_commands if license not in processed_licenses]
8080

81+
logger["processed_comment_debug"](subreddit_name, len(license_commands), len(new_licenses))
82+
8183
if new_licenses:
8284
for license in new_licenses:
8385
processed_licenses.add(license)
@@ -142,7 +144,7 @@ def update_gist(license_commands):
142144
# Exponential backoff
143145
time.sleep(5 * retry_count)
144146

145-
logger["error"]("Failed to update gist after multiple retries")
147+
logger["latest_gist_update_failed"]()
146148

147149
# Update the "Latest Steam Games" Gist with recent licenses
148150
def update_latest_gist(license_commands):
@@ -181,7 +183,7 @@ def queue_worker():
181183
try:
182184
update_gist(license_commands)
183185
except Exception as e:
184-
logger["error"](f"Error processing queue: {str(e)}")
186+
logger["queue_processing_error"](str(e))
185187
else:
186188
time.sleep(1)
187189

@@ -195,10 +197,11 @@ def start_queue_worker():
195197
worker_thread = threading.Thread(target=queue_worker)
196198
worker_thread.daemon = True
197199
worker_thread.start()
198-
logger["info"]("Queue worker started.")
200+
logger["queue_worker_started"]()
199201

200202
# Stream comments from a single subreddit
201203
def stream_comments(subreddit_name):
204+
logger["starting_stream"](subreddit_name)
202205
subreddit = reddit.subreddit(subreddit_name)
203206
retry_count = 0
204207
while True:
@@ -217,6 +220,7 @@ def stream_comments(subreddit_name):
217220
# Catch up on missed comments
218221
def catch_up_comments():
219222
global LAST_PROCESSED
223+
logger["starting_catchup"]()
220224
for subreddit_name in subreddits:
221225
try:
222226
subreddit = reddit.subreddit(subreddit_name)
@@ -227,6 +231,7 @@ def catch_up_comments():
227231
logger["fetch_error"](subreddit_name, e)
228232
time.sleep(5) # Small delay before trying next subreddit
229233
LAST_PROCESSED = int(time.time())
234+
logger["catchup_completed"]()
230235

231236
# Hybrid monitoring function
232237
def hybrid_reddit_monitor():
@@ -282,11 +287,11 @@ def start_health_server(port):
282287
server_thread = Thread(target=server.serve_forever)
283288
server_thread.daemon = True
284289
server_thread.start()
285-
logger["info"](f"Health check server started on port {port}")
290+
logger["health_server_started"](port)
286291

287292
# Main entry point
288293
if __name__ == "__main__":
289-
logger["info"](f"ASFScan v{VERSION} started and monitoring subreddits...")
294+
logger["bot_started"](VERSION)
290295

291296
start_queue_worker()
292297
start_polling()
@@ -298,4 +303,4 @@ def start_health_server(port):
298303
while True:
299304
time.sleep(60)
300305
except KeyboardInterrupt:
301-
logger["info"]("Bot shutting down...")
306+
logger["bot_shutting_down"]()

‎lib/logger.py‎

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,50 @@ def no_new_licenses():
6666
def rate_limit(service, retry_after):
6767
warn(f"{service} API rate limit exceeded. Pausing operations for {retry_after} seconds before next attempt.")
6868

69+
# Log when starting comment stream for a subreddit
70+
def starting_stream(subreddit_name):
71+
info(f"Starting comment stream for r/{subreddit_name}")
72+
73+
# Log when starting catch-up on missed comments
74+
def starting_catchup():
75+
info("Starting catch-up on missed comments")
76+
77+
# Log when catch-up is completed
78+
def catchup_completed():
79+
info("Catch-up completed")
80+
81+
# Log debug info for processed comment
82+
def processed_comment_debug(subreddit_name, found, new):
83+
debug(f"Processed comment from r/{subreddit_name}: found {found} license commands, {new} new")
84+
85+
# Log when gist update fails after retries
86+
def gist_update_failed():
87+
error("Failed to update gist after multiple retries")
88+
89+
# Log when latest gist update fails after retries
90+
def latest_gist_update_failed():
91+
error("Failed to update latest gist after multiple retries")
92+
93+
# Log error in queue processing
94+
def queue_processing_error(error_msg):
95+
error(f"Error processing queue: {error_msg}")
96+
97+
# Log when queue worker starts
98+
def queue_worker_started():
99+
info("Queue worker started.")
100+
101+
# Log when health server starts
102+
def health_server_started(port):
103+
info(f"Health check server started on port {port}")
104+
105+
# Log when bot starts
106+
def bot_started(version):
107+
info(f"ASFScan v{version} started and monitoring subreddits...")
108+
109+
# Log when bot shuts down
110+
def bot_shutting_down():
111+
info("Bot shutting down...")
112+
69113
# Make the logger functions available as module attributes
70114
logger = {
71115
"info": info,
@@ -77,5 +121,16 @@ def rate_limit(service, retry_after):
77121
"processing_comment": processing_comment,
78122
"gist_update_success": gist_update_success,
79123
"no_new_licenses": no_new_licenses,
80-
"rate_limit": rate_limit
124+
"rate_limit": rate_limit,
125+
"starting_stream": starting_stream,
126+
"starting_catchup": starting_catchup,
127+
"catchup_completed": catchup_completed,
128+
"processed_comment_debug": processed_comment_debug,
129+
"gist_update_failed": gist_update_failed,
130+
"latest_gist_update_failed": latest_gist_update_failed,
131+
"queue_processing_error": queue_processing_error,
132+
"queue_worker_started": queue_worker_started,
133+
"health_server_started": health_server_started,
134+
"bot_started": bot_started,
135+
"bot_shutting_down": bot_shutting_down
81136
}

0 commit comments

Comments
 (0)