mirror of
https://github.com/dograh-hq/dograh.git
synced 2026-06-22 08:38:13 +02:00
fix: add error in cloudonix cdr report
This commit is contained in:
parent
b1c982a52e
commit
e9c5da16c5
7 changed files with 94 additions and 17 deletions
|
|
@ -287,6 +287,8 @@ class EmbedTokenClient(BaseDBClient):
|
|||
Returns:
|
||||
Dictionary with usage statistics
|
||||
"""
|
||||
from sqlalchemy import func
|
||||
|
||||
async with self.async_session() as session:
|
||||
# Get the token
|
||||
result = await session.execute(
|
||||
|
|
@ -302,16 +304,16 @@ class EmbedTokenClient(BaseDBClient):
|
|||
if not token:
|
||||
return {}
|
||||
|
||||
# Count active sessions
|
||||
# Count active sessions using SQL COUNT
|
||||
active_sessions_result = await session.execute(
|
||||
select(EmbedSessionModel).where(
|
||||
select(func.count(EmbedSessionModel.id)).where(
|
||||
and_(
|
||||
EmbedSessionModel.embed_token_id == token_id,
|
||||
EmbedSessionModel.expires_at > datetime.now(UTC),
|
||||
)
|
||||
)
|
||||
)
|
||||
active_sessions = len(active_sessions_result.scalars().all())
|
||||
active_sessions = active_sessions_result.scalar() or 0
|
||||
|
||||
return {
|
||||
"token_id": token_id,
|
||||
|
|
|
|||
|
|
@ -224,23 +224,56 @@ class LoopTalkClient(BaseDBClient):
|
|||
self, load_test_group_id: str, organization_id: int
|
||||
) -> Dict[str, Any]:
|
||||
"""Get statistics for a load test group."""
|
||||
from sqlalchemy import case, func
|
||||
|
||||
async with self.async_session() as session:
|
||||
# Get all sessions in the group
|
||||
result = await session.execute(
|
||||
select(LoopTalkTestSession).where(
|
||||
# Get status counts using SQL aggregation
|
||||
counts_result = await session.execute(
|
||||
select(
|
||||
func.count().label("total"),
|
||||
func.sum(
|
||||
case((LoopTalkTestSession.status == "pending", 1), else_=0)
|
||||
).label("pending"),
|
||||
func.sum(
|
||||
case((LoopTalkTestSession.status == "running", 1), else_=0)
|
||||
).label("running"),
|
||||
func.sum(
|
||||
case((LoopTalkTestSession.status == "completed", 1), else_=0)
|
||||
).label("completed"),
|
||||
func.sum(
|
||||
case((LoopTalkTestSession.status == "failed", 1), else_=0)
|
||||
).label("failed"),
|
||||
).where(
|
||||
LoopTalkTestSession.load_test_group_id == load_test_group_id,
|
||||
LoopTalkTestSession.organization_id == organization_id,
|
||||
)
|
||||
)
|
||||
sessions = result.scalars().all()
|
||||
counts = counts_result.one()
|
||||
|
||||
# Get session details (still needed for the sessions list)
|
||||
sessions_result = await session.execute(
|
||||
select(
|
||||
LoopTalkTestSession.id,
|
||||
LoopTalkTestSession.name,
|
||||
LoopTalkTestSession.status,
|
||||
LoopTalkTestSession.test_index,
|
||||
LoopTalkTestSession.created_at,
|
||||
LoopTalkTestSession.started_at,
|
||||
LoopTalkTestSession.completed_at,
|
||||
LoopTalkTestSession.error,
|
||||
).where(
|
||||
LoopTalkTestSession.load_test_group_id == load_test_group_id,
|
||||
LoopTalkTestSession.organization_id == organization_id,
|
||||
)
|
||||
)
|
||||
sessions = sessions_result.all()
|
||||
|
||||
# Calculate stats
|
||||
stats = {
|
||||
"total": len(sessions),
|
||||
"pending": sum(1 for s in sessions if s.status == "pending"),
|
||||
"running": sum(1 for s in sessions if s.status == "running"),
|
||||
"completed": sum(1 for s in sessions if s.status == "completed"),
|
||||
"failed": sum(1 for s in sessions if s.status == "failed"),
|
||||
"total": counts.total or 0,
|
||||
"pending": counts.pending or 0,
|
||||
"running": counts.running or 0,
|
||||
"completed": counts.completed or 0,
|
||||
"failed": counts.failed or 0,
|
||||
"sessions": [
|
||||
{
|
||||
"id": s.id,
|
||||
|
|
|
|||
|
|
@ -377,6 +377,8 @@ class WorkflowRunModel(Base):
|
|||
text("(gathered_context->>'call_id')"),
|
||||
postgresql_where=text("gathered_context->>'call_id' IS NOT NULL"),
|
||||
),
|
||||
Index("idx_workflow_runs_workflow_id", "workflow_id"),
|
||||
Index("idx_workflow_runs_campaign_id", "campaign_id"),
|
||||
)
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue