mirror of
https://github.com/open-webui/open-webui.git
synced 2025-12-17 14:55:23 +00:00
feat : Retry acquiring usage cleanup lock to handle potential stale locks
This commit is contained in:
parent
21d616f8ed
commit
789e6a0db3
1 changed files with 22 additions and 4 deletions
|
|
@ -1,4 +1,6 @@
|
||||||
import asyncio
|
import asyncio
|
||||||
|
import random
|
||||||
|
|
||||||
import socketio
|
import socketio
|
||||||
import logging
|
import logging
|
||||||
import sys
|
import sys
|
||||||
|
|
@ -105,10 +107,26 @@ else:
|
||||||
|
|
||||||
|
|
||||||
async def periodic_usage_pool_cleanup():
|
async def periodic_usage_pool_cleanup():
|
||||||
if not aquire_func():
|
max_retries = 2
|
||||||
log.debug("Usage pool cleanup lock already exists. Not running it.")
|
retry_delay = random.uniform(
|
||||||
return
|
WEBSOCKET_REDIS_LOCK_TIMEOUT / 2, WEBSOCKET_REDIS_LOCK_TIMEOUT
|
||||||
log.debug("Running periodic_usage_pool_cleanup")
|
)
|
||||||
|
for attempt in range(max_retries + 1):
|
||||||
|
if aquire_func():
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
if attempt < max_retries:
|
||||||
|
log.debug(
|
||||||
|
f"Cleanup lock already exists. Retry {attempt + 1} after {retry_delay}s..."
|
||||||
|
)
|
||||||
|
await asyncio.sleep(retry_delay)
|
||||||
|
else:
|
||||||
|
log.warning(
|
||||||
|
"Failed to acquire cleanup lock after retries. Skipping cleanup."
|
||||||
|
)
|
||||||
|
return
|
||||||
|
|
||||||
|
log.debug("Running periodic_cleanup")
|
||||||
try:
|
try:
|
||||||
while True:
|
while True:
|
||||||
if not renew_func():
|
if not renew_func():
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue