a digital person for bluesky

Process notifications in reverse chronological order (newest first)

- Add queue_file_sort_key() function for consistent sorting
- Sort by priority first (0 before 1), then newest timestamp first
- Updated load_and_process_queued_notifications to use new sorting
- Updated queue reload during processing to maintain sort order
- Most recent notifications now processed first within each priority group

This ensures fresh mentions and replies get immediate attention
while maintaining priority for @cameron.pfiffer.org.

🐾 Generated with [Letta Code](https://letta.com)

Co-Authored-By: Letta <noreply@letta.com>

+24 -5
+24 -5
bsky.py
··· 1054 1054 logger.error(f"Error detaching user blocks: {e}") 1055 1055 1056 1056 1057 + 1058 + def queue_file_sort_key(filepath): 1059 + """ 1060 + Sort key for queue files: priority first (0 before 1), then newest first within each priority. 1061 + Filename format: {priority}_{YYYYMMDD}_{HHMMSS}_{reason}_{hash}.json 1062 + """ 1063 + parts = filepath.name.split('_') 1064 + if len(parts) >= 3: 1065 + priority = int(parts[0]) # 0 or 1 1066 + date_part = parts[1] # YYYYMMDD 1067 + time_part = parts[2] # HHMMSS 1068 + timestamp = int(date_part + time_part) # YYYYMMDDHHMMSS as integer 1069 + # Return (priority ascending, timestamp descending) 1070 + return (priority, -timestamp) 1071 + return (1, 0) # Fallback: treat as normal priority, oldest 1072 + 1057 1073 def notification_to_dict(notification): 1058 1074 """Convert a notification object to a dictionary for JSON serialization.""" 1059 1075 return { ··· 1167 1183 1168 1184 1169 1185 def load_and_process_queued_notifications(void_agent, atproto_client, testing_mode=False): 1170 - """Load and process all notifications from the queue in priority order.""" 1186 + """Load and process all notifications from the queue in priority order (newest first).""" 1171 1187 try: 1172 1188 # Get all JSON files in queue directory (excluding processed_notifications.json) 1173 - # Files are sorted by name, which puts priority files first (0_ prefix before 1_ prefix) 1174 - all_queue_files = sorted([f for f in QUEUE_DIR.glob("*.json") if f.name != "processed_notifications.json"]) 1189 + all_queue_files = [f for f in QUEUE_DIR.glob("*.json") if f.name != "processed_notifications.json"] 1190 + 1191 + # Sort by priority first (0_ before 1_), then by timestamp (newest first within each priority) 1192 + all_queue_files = sorted(all_queue_files, key=queue_file_sort_key) 1175 1193 1176 1194 # Filter out and delete like notifications immediately 1177 1195 queue_files = [] ··· 1228 1246 1229 1247 if new_count > 0: 1230 1248 logger.info(f"Added {new_count} new notifications to queue") 1231 - # Reload the queue files to include the new items 1232 - updated_queue_files = sorted([f for f in QUEUE_DIR.glob("*.json") if f.name != "processed_notifications.json"]) 1249 + # Reload the queue files to include the new items with same sorting 1250 + updated_queue_files = [f for f in QUEUE_DIR.glob("*.json") if f.name != "processed_notifications.json"] 1251 + updated_queue_files = sorted(updated_queue_files, key=queue_file_sort_key) 1233 1252 queue_files = updated_queue_files 1234 1253 logger.info(f"Queue updated: now {len(queue_files)} total items") 1235 1254 except Exception as e: