fix: harden group lifecycle and registration writes
This commit is contained in:
@@ -2725,6 +2725,9 @@ func (a *adapter) TenantCallList(id t.TenantID, uid t.Uid, topic, cursor string,
|
||||
if cancel != nil {
|
||||
defer cancel()
|
||||
}
|
||||
if err := a.finalizeStaleCalls(ctx); err != nil {
|
||||
return nil, "", err
|
||||
}
|
||||
rows, err := a.db.QueryxContext(ctx,
|
||||
`SELECT id,call_id,topic,seq_id,caller_id,callee_id,call_type,status,end_reason,duration_ms,
|
||||
started_at,accepted_at,finished_at,created_at,updated_at
|
||||
@@ -2786,6 +2789,23 @@ func (a *adapter) TenantCallList(id t.TenantID, uid t.Uid, topic, cursor string,
|
||||
return records, nextCursor, nil
|
||||
}
|
||||
|
||||
func (a *adapter) finalizeStaleCalls(ctx context.Context) error {
|
||||
now := t.TimeNow()
|
||||
startedBefore := now.Add(-2 * time.Minute)
|
||||
acceptedBefore := now.Add(-12 * time.Hour)
|
||||
if _, err := a.db.ExecContext(ctx, `UPDATE im_call_records
|
||||
SET status=?,end_reason=?,duration_ms=0,finished_at=?,updated_at=?
|
||||
WHERE status=? AND started_at<? AND finished_at IS NULL`,
|
||||
t.CallStatusMissed, t.CallStatusMissed, now, now, t.CallStatusStarted, startedBefore); err != nil {
|
||||
return err
|
||||
}
|
||||
_, err := a.db.ExecContext(ctx, `UPDATE im_call_records
|
||||
SET status=?,end_reason=?,duration_ms=GREATEST(TIMESTAMPDIFF(MICROSECOND,accepted_at,?) DIV 1000,0),finished_at=?,updated_at=?
|
||||
WHERE status=? AND accepted_at IS NOT NULL AND accepted_at<? AND finished_at IS NULL`,
|
||||
t.CallStatusDisconnected, t.CallStatusDisconnected, now, now, now, t.CallStatusAccepted, acceptedBefore)
|
||||
return err
|
||||
}
|
||||
|
||||
func (a *adapter) TenantWorkbenchModules(id t.TenantID, uid t.Uid) ([]t.WorkbenchModule, int, error) {
|
||||
if !a.tenantScopedDB {
|
||||
tenantAdp, err := a.routedTenantAdapter(id)
|
||||
|
||||
Reference in New Issue
Block a user