μ λ ν μ€νΈλ₯Ό νλ€κ° μλμ κ°μ μμΈκ° λ°μνμ΅λλ€.
Operations that change non-concurrent collections must have exclusive access. A concurrent update was performed on this collection and corrupted its state. The collectionβs state is no longer correct.
κ΄λ ¨ν΄μ ꡬκΈμ κ²μν΄λ³΄λ μμΈμ΄ λͺ
ννμ§ μμ κ² κ°μ΅λλ€.
λ¬Έμ κ° λ°μν μ λν
μ€νΈ λ©μλλ μλμ κ°μ΅λλ€. NUnitμ ν΅ν΄ μμ±λμκ³ , μ²μ보λ ν΄λμ€λ μ체 μ μ ν΄λμ€λΌκ³ 보μλ©΄ λ λ― ν©λλ€.
[TestCase(419364050, EShopeeItemStatus.NORMAL)]
[TestCase(419364050, EShopeeItemStatus.UNLIST)]
public async Task InitGmarketWhiteList(long shopId, EShopeeItemStatus eShopeeItemStatus)
{
RequestGetItemList req = new()
{
ShopId = shopId,
PartnerId = _shopeeOption.PartnerId,
Offset = 0,
PageSize = 100,
UpdateTimeFrom = new DateTimeOffset(DateTime.Now.AddYears(-3)).ToUnixTimeSeconds(),
UpdateTimeTo = new DateTimeOffset(DateTime.Now.AddDays(1)).ToUnixTimeSeconds(),
ItemStatus = eShopeeItemStatus
};
TaskBase<ResponseGetItemBaseInfo> taskBaseRes = await req.FullBaseInfoScanAsync(_shopeeClient);
if (!taskBaseRes.IsSuccess)
{
Assert.False(!taskBaseRes.IsSuccess);
}
ResponseGetItemBaseInfo res = taskBaseRes.Result;
AwesomeSwagClient awesomeSwagClient = new(new HttpClient(), _companyId);
SemaphoreSlim semaphore = new(20);
List<Task> tasks = new();
foreach (ResponseGetItemBaseInfo._Item item in res.ItemList)
{
tasks.Add(Task.Run(async () =>
{
await semaphore.WaitAsync();
try
{
Product awesomeSwagSourceItem = await awesomeSwagClient.GetProductFromOrgIdDetailAsync(item.ItemSku);
if (awesomeSwagSourceItem is null)
{
EcWhiteList reqWhiteList = new()
{
Platform = EPlatform.SHOPEE,
PlatformId = item.ItemId.ToString(),
ShopId = shopId.ToString(),
ShopName = string.Empty,
};
await _ecWhiteListService.InsertAsync(reqWhiteList); // μμΈ λ°μμ§μ
}
}
finally
{
semaphore.Release();
}
}));
}
await Task.WhenAll(tasks);
Assert.True(true);
}
public async Task InsertAsync(EcWhiteList edata)
{
try
{
_context.EcWhiteLists.Add(edata);
await _context.SaveChangesAsync();
}
catch (Exception ex)
{
}
}
λ¬Έμ κ° λ°μν λ©μλλ μ£ΌμμΌλ‘ νκΈ°νκ³ λ©μλμ μ μλ μλ InsertAsync λ©μλμ
λλ€.
Cosmos DBμ Semaphoreλ₯Ό νμ©νμ¬ μΉν΅μ ν κ²°κ³Όλ₯Ό μ μ₯νλ μ½λμΈλ° μ΄λ° μλ¬κ° λ°μν©λλ€β¦
λ¬Όλ‘ λ³λ ¬μ²λ¦¬μμ΄ λκΈ°μμΌλ‘ foreachλ¬Έμμ νλμ© λ리면 λ¬Έμ κ° λ°μνμ§ μμ΅λλ€.
μ λ°μνλ κ±ΈκΉμ?