- ABP Framework version: v7.4.5
 - UI Type: Angular
 - Database System: PostgreSQL
 - Tiered (for MVC) or Auth Server Separated (for Angular): yes
 
I've an handler to sync data from microservices
 public async Task HandleEventAsync(ProductEto eventData)
    {
        if (eventData != null)
        {
            using (var unitOfWork = _unitOfWorkManager.Begin())
            {
                _currentTenant.Change(eventData.TenantId);
                try
                {
                    var gmd = _objectMapper.Map<ProductEto, ProductSync>(eventData);
                    await _productSyncRepository.InsertAsync(gmd);
                }
                catch (Exception ex)
                {
                    Logger.LogError(ex, "Handle Event ProductEto Error");
                }
                finally
                {
                    await unitOfWork.CompleteAsync();
                }
            }
        }
        else
        {
            Logger.LogWarning("Input data is null into handle event ProductEto");
        }
    }
In this case I've a PK duplicate so Postgres raise an excetion but this happen in finally and my handler continue to retry process my data.
Also I observe that if I call InsertAsyc/UpdateAsync and not return to a local varibile update or insert in some case does't work, if I return the value it always work.
3 Answer(s)
- 
    0
hi
You can try the code below
public async Task HandleEventAsync(ProductEto eventData) { if (eventData != null) { using (var unitOfWork = _unitOfWorkManager.Begin(requiresNew: true)) { _currentTenant.Change(eventData.TenantId); try { var gmd = _objectMapper.Map<ProductEto, ProductSync>(eventData); await _productSyncRepository.InsertAsync(gmd); await unitOfWork.CompleteAsync(); } catch (Exception ex) { Logger.LogError(ex, "Handle Event ProductEto Error"); } } } else { Logger.LogWarning("Input data is null into handle event ProductEto"); } } - 
    0
Hi
I'll try but I think it works beacuse task raise exception inside the try but is this the best approch to use UOW in using?
About Insert/Update issue any idea?
 - 
    0
If there is an
unhandled exceptionthe uow should fall back/fail.The
InsertAsyc/UpdateAsyncmethod has anautoSaveparameter. You can set it totrue.https://docs.abp.io/en/abp/latest/Unit-Of-Work#alternative-to-the-savechanges