Refactor wishlist auto-processing lock logic
Improves handling of concurrent wishlist and watchlist operations by moving scheduling outside the lock and using flags to avoid deadlocks. This change ensures that scheduling the next wishlist processing does not occur while holding the lock, reducing risk of deadlock and improving code clarity.
This commit is contained in:
parent
8e67c34d72
commit
cee7774c93
1 changed files with 18 additions and 10 deletions
|
|
@ -7626,23 +7626,31 @@ def _process_wishlist_automatically():
|
|||
print("🤖 [Auto-Wishlist] Timer triggered - starting automatic wishlist processing...")
|
||||
|
||||
try:
|
||||
# Check conditions and set flag
|
||||
should_skip_already_running = False
|
||||
should_skip_watchlist_conflict = False
|
||||
|
||||
with wishlist_timer_lock:
|
||||
if wishlist_auto_processing:
|
||||
print("⚠️ Wishlist auto-processing already running, skipping.")
|
||||
schedule_next_wishlist_processing()
|
||||
return
|
||||
should_skip_already_running = True
|
||||
|
||||
# Check if watchlist scan is currently running (using smart detection)
|
||||
if is_watchlist_actually_scanning():
|
||||
elif is_watchlist_actually_scanning():
|
||||
print("👁️ Watchlist scan in progress, skipping automatic wishlist processing to avoid conflicts.")
|
||||
schedule_next_wishlist_processing()
|
||||
return
|
||||
should_skip_watchlist_conflict = True
|
||||
|
||||
# Set flag and timestamp
|
||||
import time
|
||||
wishlist_auto_processing = True
|
||||
wishlist_auto_processing_timestamp = time.time()
|
||||
print(f"🔒 [Auto-Wishlist] Flag set at timestamp {wishlist_auto_processing_timestamp}")
|
||||
else:
|
||||
# Set flag and timestamp
|
||||
import time
|
||||
wishlist_auto_processing = True
|
||||
wishlist_auto_processing_timestamp = time.time()
|
||||
print(f"🔒 [Auto-Wishlist] Flag set at timestamp {wishlist_auto_processing_timestamp}")
|
||||
|
||||
# Schedule next run OUTSIDE the lock to avoid deadlock
|
||||
if should_skip_already_running or should_skip_watchlist_conflict:
|
||||
schedule_next_wishlist_processing()
|
||||
return
|
||||
|
||||
# Use app context for database operations
|
||||
with app.app_context():
|
||||
|
|
|
|||
Loading…
Reference in a new issue