← Все статьи

Идемпотентность при повторной доставке события

PHP
<?php

function exportDealOnce(int $dealId, string $externalKey): void
{
    if (ExchangeJournal::exists($externalKey)) {
        return;
    }

    $response = ExternalApi::send(DealExporter::build($dealId));
    ExchangeJournal::add([
        'UF_KEY' => $externalKey,
        'UF_DEAL_ID' => $dealId,
        'UF_STATUS' => $response['status'],
    ]);
}