@@ -574,25 +574,26 @@ func (s *Service) stopConversationsAfterConsentWithdrawal(
|
||||
return []string{}, nil
|
||||
}
|
||||
type candidate struct {
|
||||
internalID, publicID, status string
|
||||
internalID, publicID, status, runtimeType string
|
||||
}
|
||||
rows, err := tx.Query(ctx, `
|
||||
SELECT c.id::text,c.public_id::text,c.status
|
||||
SELECT c.id::text,c.public_id::text,c.status,c.runtime_type
|
||||
FROM conversation c
|
||||
JOIN consent_snapshot cs ON cs.id=c.consent_snapshot_id AND cs.tenant_id=c.tenant_id
|
||||
JOIN rtc_task rt ON rt.conversation_id=c.id
|
||||
LEFT JOIN rtc_task rt ON rt.conversation_id=c.id
|
||||
LEFT JOIN hardware_agent_session hs ON hs.conversation_id=c.id
|
||||
WHERE c.tenant_id=$1::uuid AND c.subject_id=$2::uuid
|
||||
AND c.status IN ('PREPARING','ROOM_ISSUED','STARTING_AGENT','ACTIVE')
|
||||
AND cs.effective_consents @> jsonb_build_object($3::text,true)
|
||||
ORDER BY c.created_at,c.id
|
||||
FOR UPDATE OF c,rt`, tenantID, subjectID, consentType)
|
||||
FOR UPDATE OF c`, tenantID, subjectID, consentType)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("find conversations affected by consent withdrawal: %w", err)
|
||||
}
|
||||
candidates := make([]candidate, 0)
|
||||
for rows.Next() {
|
||||
var item candidate
|
||||
if err := rows.Scan(&item.internalID, &item.publicID, &item.status); err != nil {
|
||||
if err := rows.Scan(&item.internalID, &item.publicID, &item.status, &item.runtimeType); err != nil {
|
||||
rows.Close()
|
||||
return nil, fmt.Errorf("scan consent withdrawal conversation: %w", err)
|
||||
}
|
||||
@@ -621,7 +622,11 @@ func (s *Service) stopConversationsAfterConsentWithdrawal(
|
||||
if tag.RowsAffected() != 1 {
|
||||
return nil, fmt.Errorf("conversation changed during consent withdrawal")
|
||||
}
|
||||
if toStatus == "EXPIRED" {
|
||||
if item.runtimeType == "volc_hardware_agent" && toStatus == "EXPIRED" {
|
||||
_, err = tx.Exec(ctx, `UPDATE hardware_agent_session SET status='EXPIRED',updated_at=now() WHERE conversation_id=$1::uuid`, item.internalID)
|
||||
} else if item.runtimeType == "volc_hardware_agent" {
|
||||
_, err = tx.Exec(ctx, `UPDATE hardware_agent_session SET status='STOPPING',updated_at=now() WHERE conversation_id=$1::uuid`, item.internalID)
|
||||
} else if toStatus == "EXPIRED" {
|
||||
_, err = tx.Exec(ctx, `UPDATE rtc_task SET status='COMPLETED',lease_expires_at=NULL,updated_at=now() WHERE conversation_id=$1::uuid`, item.internalID)
|
||||
} else {
|
||||
_, err = tx.Exec(ctx, `UPDATE rtc_task SET status=CASE WHEN status='ACTIVE' THEN 'STOPPING' ELSE 'UNKNOWN' END,lease_expires_at=NULL,updated_at=now() WHERE conversation_id=$1::uuid`, item.internalID)
|
||||
@@ -634,7 +639,7 @@ func (s *Service) stopConversationsAfterConsentWithdrawal(
|
||||
VALUES($1::uuid,$2,$3,$4,'platform')`, item.internalID, item.status, toStatus, "consent withdrawn: "+consentType); err != nil {
|
||||
return nil, fmt.Errorf("record consent withdrawal stop: %w", err)
|
||||
}
|
||||
if toStatus == "STOPPING" {
|
||||
if toStatus == "STOPPING" && item.runtimeType != "volc_hardware_agent" {
|
||||
deduplicationKey := "consent-withdrawal-stop:" + item.internalID + ":" + consentType
|
||||
payload, _ := json.Marshal(map[string]string{
|
||||
"conversation_id": item.publicID,
|
||||
|
||||
Reference in New Issue
Block a user