Текущая стабильная сборка с исправлением интеграционных косяков
This commit is contained in:
@@ -5,7 +5,8 @@ import uuid
|
||||
from dataclasses import dataclass, field
|
||||
from typing import Any
|
||||
|
||||
from sqlalchemy import text
|
||||
from sqlalchemy import bindparam, text
|
||||
from sqlalchemy.dialects.postgresql import JSONB
|
||||
|
||||
from app.config import Settings
|
||||
from app.crm import CrmClient, CrmOutcome, CrmResult
|
||||
@@ -19,6 +20,26 @@ from app.domain import (
|
||||
)
|
||||
from app.repository import LeasedTask, LeasedWebhook, Profile, Repository
|
||||
|
||||
INSERT_CRM_COMMAND = text(
|
||||
"""
|
||||
INSERT INTO bitrix_sync.crm_commands
|
||||
(id,workflow_id,command_type,safe_request,status,attempt_count,
|
||||
next_attempt_at,created_at,updated_at)
|
||||
VALUES (:id,:workflow_id,:type,:safe_request,'in_flight',1,now(),now(),now())
|
||||
"""
|
||||
).bindparams(bindparam("safe_request", type_=JSONB()))
|
||||
|
||||
UPDATE_CRM_COMMAND = text(
|
||||
"""
|
||||
UPDATE bitrix_sync.crm_commands
|
||||
SET status=:status,safe_error_code=:error,http_status=:http_status,
|
||||
safe_response=:safe_response,
|
||||
completed_at=CASE WHEN :terminal THEN now() END,
|
||||
updated_at=now()
|
||||
WHERE id=:id
|
||||
"""
|
||||
).bindparams(bindparam("safe_response", type_=JSONB()))
|
||||
|
||||
|
||||
class BusinessConflict(Exception):
|
||||
def __init__(self, code: str, candidates: list[str] | None = None) -> None:
|
||||
@@ -452,14 +473,7 @@ class WorkflowEngine:
|
||||
command_id = uuid.uuid4()
|
||||
async with self.repository.transaction() as connection:
|
||||
await connection.execute(
|
||||
text(
|
||||
"""
|
||||
INSERT INTO bitrix_sync.crm_commands
|
||||
(id,workflow_id,command_type,safe_request,status,attempt_count,
|
||||
next_attempt_at,created_at,updated_at)
|
||||
VALUES (:id,:workflow_id,:type,:safe_request,'in_flight',1,now(),now(),now())
|
||||
"""
|
||||
),
|
||||
INSERT_CRM_COMMAND,
|
||||
{
|
||||
"id": command_id,
|
||||
"workflow_id": workflow_id,
|
||||
@@ -479,16 +493,7 @@ class WorkflowEngine:
|
||||
status = result.outcome.value
|
||||
async with self.repository.transaction() as connection:
|
||||
await connection.execute(
|
||||
text(
|
||||
"""
|
||||
UPDATE bitrix_sync.crm_commands
|
||||
SET status=:status,safe_error_code=:error,http_status=:http_status,
|
||||
safe_response=:safe_response,
|
||||
completed_at=CASE WHEN :terminal THEN now() END,
|
||||
updated_at=now()
|
||||
WHERE id=:id
|
||||
"""
|
||||
),
|
||||
UPDATE_CRM_COMMAND,
|
||||
{
|
||||
"id": command_id,
|
||||
"status": status,
|
||||
|
||||
Reference in New Issue
Block a user