mirror of https://github.com/kortix-ai/suna.git
Merge branch 'PRODUCTION'
This commit is contained in:
commit
1186ffefa3
|
@ -10,7 +10,7 @@ services:
|
||||||
memory: 32G
|
memory: 32G
|
||||||
|
|
||||||
worker:
|
worker:
|
||||||
command: python -m dramatiq --processes 10 --threads 32 run_agent_background
|
command: python -m dramatiq --processes 40 --threads 8 run_agent_background
|
||||||
deploy:
|
deploy:
|
||||||
resources:
|
resources:
|
||||||
limits:
|
limits:
|
||||||
|
|
|
@ -29,6 +29,10 @@ async def initialize():
|
||||||
"""Initialize the agent API with resources from the main API."""
|
"""Initialize the agent API with resources from the main API."""
|
||||||
global db, instance_id, _initialized
|
global db, instance_id, _initialized
|
||||||
if _initialized:
|
if _initialized:
|
||||||
|
try: await redis.client.ping()
|
||||||
|
except Exception as e:
|
||||||
|
logger.warning(f"Redis connection failed, re-initializing: {e}")
|
||||||
|
await redis.initialize_async(force=True)
|
||||||
return
|
return
|
||||||
|
|
||||||
# Use provided instance_id or generate a new one
|
# Use provided instance_id or generate a new one
|
||||||
|
@ -58,7 +62,11 @@ async def run_agent_background(
|
||||||
target_agent_id: Optional[str] = None
|
target_agent_id: Optional[str] = None
|
||||||
):
|
):
|
||||||
"""Run the agent in the background using Redis for state."""
|
"""Run the agent in the background using Redis for state."""
|
||||||
await initialize()
|
try:
|
||||||
|
await initialize()
|
||||||
|
except Exception as e:
|
||||||
|
logger.critical(f"Failed to initialize Redis connection: {e}")
|
||||||
|
raise e
|
||||||
|
|
||||||
sentry.sentry.set_tag("thread_id", thread_id)
|
sentry.sentry.set_tag("thread_id", thread_id)
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@ from utils.logger import logger
|
||||||
from typing import List, Any
|
from typing import List, Any
|
||||||
|
|
||||||
# Redis client
|
# Redis client
|
||||||
client = None
|
client: redis.Redis | None = None
|
||||||
_initialized = False
|
_initialized = False
|
||||||
_init_lock = asyncio.Lock()
|
_init_lock = asyncio.Lock()
|
||||||
|
|
||||||
|
@ -47,11 +47,19 @@ def initialize():
|
||||||
return client
|
return client
|
||||||
|
|
||||||
|
|
||||||
async def initialize_async():
|
async def initialize_async(force: bool = False):
|
||||||
"""Initialize Redis connection asynchronously."""
|
"""Initialize Redis connection asynchronously."""
|
||||||
global client, _initialized
|
global client, _initialized
|
||||||
|
|
||||||
async with _init_lock:
|
async with _init_lock:
|
||||||
|
if _initialized and force:
|
||||||
|
logger.info("Redis connection already initialized, closing and re-initializing")
|
||||||
|
_initialized = False
|
||||||
|
try:
|
||||||
|
await close()
|
||||||
|
except Exception as e:
|
||||||
|
logger.warning(f"Failed to close Redis connection, proceeding with re-initialization anyway: {e}")
|
||||||
|
|
||||||
if not _initialized:
|
if not _initialized:
|
||||||
logger.info("Initializing Redis connection")
|
logger.info("Initializing Redis connection")
|
||||||
initialize()
|
initialize()
|
||||||
|
|
Loading…
Reference in New Issue