54 lines
1.6 KiB
Python
54 lines
1.6 KiB
Python
|
|
"""Verify Redis and Celery integration."""
|
||
|
|
|
||
|
|
import asyncio
|
||
|
|
import os
|
||
|
|
import sys
|
||
|
|
|
||
|
|
# Add project root to path
|
||
|
|
sys.path.insert(0, os.getcwd())
|
||
|
|
|
||
|
|
from src.core.redis import get_redis_client
|
||
|
|
from src.worker.app import app
|
||
|
|
from src.worker.tasks import train_model_task
|
||
|
|
|
||
|
|
async def verify_redis():
|
||
|
|
"""Verify Redis connection."""
|
||
|
|
print("Verifying Redis connection...")
|
||
|
|
try:
|
||
|
|
redis = get_redis_client()
|
||
|
|
client = redis.get_client()
|
||
|
|
await client.set("test_key", "hello_redis")
|
||
|
|
value = await client.get("test_key")
|
||
|
|
print(f"Redis write/read success: {value}")
|
||
|
|
await client.delete("test_key")
|
||
|
|
await redis.close()
|
||
|
|
return True
|
||
|
|
except Exception as e:
|
||
|
|
print(f"Redis verification failed: {e}")
|
||
|
|
return False
|
||
|
|
|
||
|
|
def verify_celery_task_queuing():
|
||
|
|
"""Verify Celery task queuing."""
|
||
|
|
print("\nVerifying Celery task queuing...")
|
||
|
|
try:
|
||
|
|
# Submit task (won't run unless worker is active, but we check queuing)
|
||
|
|
task = train_model_task.delay(force_retrain=False, bootstrap=False)
|
||
|
|
print(f"Task submitted. ID: {task.id}")
|
||
|
|
print(f"Task status: {task.status}")
|
||
|
|
return True
|
||
|
|
except Exception as e:
|
||
|
|
print(f"Celery task submission failed: {e}")
|
||
|
|
return False
|
||
|
|
|
||
|
|
async def main():
|
||
|
|
redis_ok = await verify_redis()
|
||
|
|
celery_ok = verify_celery_task_queuing()
|
||
|
|
|
||
|
|
if redis_ok and celery_ok:
|
||
|
|
print("\nSUCCESS: Redis and Celery integration verified.")
|
||
|
|
else:
|
||
|
|
print("\nFAILURE: One or more components failed verification.")
|
||
|
|
|
||
|
|
if __name__ == "__main__":
|
||
|
|
asyncio.run(main())
|