Spaces:
Sleeping
Sleeping
axeronis commited on
Commit ·
88e5a40
1
Parent(s): 1c33429
fix: remove google_sheets remnants completely
Browse files- backend/app/main.py +0 -51
- backend/app/models/tenant.py +0 -4
backend/app/main.py
CHANGED
|
@@ -225,7 +225,6 @@ async def on_startup():
|
|
| 225 |
asyncio.create_task(reactivation_scheduler_loop())
|
| 226 |
asyncio.create_task(hot_leads_scheduler_loop()) # Hourly for hot leads
|
| 227 |
asyncio.create_task(subscription_expiry_scheduler_loop()) # Daily expiry warnings
|
| 228 |
-
asyncio.create_task(google_sheets_sync_scheduler_loop()) # Every 2 min for inventory sync
|
| 229 |
|
| 230 |
|
| 231 |
@app.on_event("shutdown")
|
|
@@ -371,56 +370,6 @@ async def subscription_expiry_scheduler_loop():
|
|
| 371 |
logger.error(f"Subscription expiry scheduler error: {e}")
|
| 372 |
await asyncio.sleep(60 * 60) # Retry in 1 hour
|
| 373 |
|
| 374 |
-
|
| 375 |
-
async def google_sheets_sync_scheduler_loop():
|
| 376 |
-
"""
|
| 377 |
-
Background loop to sync inventory from Google Sheets every 2 minutes.
|
| 378 |
-
Only syncs tenants with google_sheets_config.sync_enabled = true.
|
| 379 |
-
"""
|
| 380 |
-
from app.core.database import async_session_factory
|
| 381 |
-
from sqlmodel import select
|
| 382 |
-
from app.models.tenant import Tenant
|
| 383 |
-
from app.api.google_sheets import sync_inventory
|
| 384 |
-
from app.services.google_sheets_service import get_google_sheets_service
|
| 385 |
-
|
| 386 |
-
logger.info("📊 Google Sheets Sync Scheduler initialized (runs every 2 min)")
|
| 387 |
-
|
| 388 |
-
# Wait 1 minute after startup before first run
|
| 389 |
-
await asyncio.sleep(60)
|
| 390 |
-
|
| 391 |
-
while True:
|
| 392 |
-
try:
|
| 393 |
-
service = get_google_sheets_service()
|
| 394 |
-
|
| 395 |
-
async with async_session_factory() as session:
|
| 396 |
-
# Find all tenants with google sheets sync enabled
|
| 397 |
-
stmt = select(Tenant).where(Tenant.is_active == True)
|
| 398 |
-
result = await session.execute(stmt)
|
| 399 |
-
tenants = result.scalars().all()
|
| 400 |
-
|
| 401 |
-
synced_count = 0
|
| 402 |
-
for tenant in tenants:
|
| 403 |
-
config = tenant.google_sheets_config
|
| 404 |
-
if config and config.get("sync_enabled", False):
|
| 405 |
-
try:
|
| 406 |
-
await sync_inventory(tenant, session, service)
|
| 407 |
-
synced_count += 1
|
| 408 |
-
except Exception as e:
|
| 409 |
-
logger.warning(f"Sheet sync failed for tenant {tenant.id}: {e}")
|
| 410 |
-
|
| 411 |
-
if synced_count > 0:
|
| 412 |
-
logger.info(f"📊 Synced sheets for {synced_count} tenants")
|
| 413 |
-
|
| 414 |
-
# Sleep 2 minutes
|
| 415 |
-
await asyncio.sleep(2 * 60)
|
| 416 |
-
|
| 417 |
-
except asyncio.CancelledError:
|
| 418 |
-
logger.info("Google Sheets sync scheduler cancelled")
|
| 419 |
-
break
|
| 420 |
-
except Exception as e:
|
| 421 |
-
logger.error(f"Google Sheets sync scheduler error: {e}")
|
| 422 |
-
await asyncio.sleep(5 * 60) # Retry in 5 minutes
|
| 423 |
-
|
| 424 |
@app.get("/")
|
| 425 |
async def root():
|
| 426 |
"""Health check endpoint."""
|
|
|
|
| 225 |
asyncio.create_task(reactivation_scheduler_loop())
|
| 226 |
asyncio.create_task(hot_leads_scheduler_loop()) # Hourly for hot leads
|
| 227 |
asyncio.create_task(subscription_expiry_scheduler_loop()) # Daily expiry warnings
|
|
|
|
| 228 |
|
| 229 |
|
| 230 |
@app.on_event("shutdown")
|
|
|
|
| 370 |
logger.error(f"Subscription expiry scheduler error: {e}")
|
| 371 |
await asyncio.sleep(60 * 60) # Retry in 1 hour
|
| 372 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 373 |
@app.get("/")
|
| 374 |
async def root():
|
| 375 |
"""Health check endpoint."""
|
backend/app/models/tenant.py
CHANGED
|
@@ -117,11 +117,7 @@ class Tenant(SQLModel, table=True):
|
|
| 117 |
voice_enabled: bool = Field(default=True) # Enable/disable AI voice responses
|
| 118 |
voice_reference_url: Optional[str] = Field(default=None) # URL to custom voice audio (for voice cloning)
|
| 119 |
|
| 120 |
-
# Google Sheets Integration (Inventory Sync)
|
| 121 |
-
google_sheets_config: Optional[Dict[str, Any]] = Field(default=None, sa_column=Column(JSON))
|
| 122 |
-
# Format: {url, sheet_name, mapping: {name: "A", price: "B", quantity: "C"}, sync_enabled, last_sync}
|
| 123 |
|
| 124 |
-
|
| 125 |
# Status
|
| 126 |
is_active: bool = Field(default=True)
|
| 127 |
created_at: datetime = Field(default_factory=datetime.utcnow)
|
|
|
|
| 117 |
voice_enabled: bool = Field(default=True) # Enable/disable AI voice responses
|
| 118 |
voice_reference_url: Optional[str] = Field(default=None) # URL to custom voice audio (for voice cloning)
|
| 119 |
|
|
|
|
|
|
|
|
|
|
| 120 |
|
|
|
|
| 121 |
# Status
|
| 122 |
is_active: bool = Field(default=True)
|
| 123 |
created_at: datetime = Field(default_factory=datetime.utcnow)
|