Base solution for your next web application
Open Closed

Background job or worker and iterrating through tenant databases PARALLEL #7555


User avatar
0
leonkosak created
MyPeriodicBackgroundMethod()
{
    var tenantIdList = new List<int>();  //all **tenants** which have **dedicated database**
    
    foreach (var tenantId in tenantIdList)
    {
        using (_unitOfWorkManager.Current.SetTenantId(tenantId)
        {
	         //code for specific tenant - inserts, updates, deletes in this tenant database
        }
    }
}

Is somehow possible and safe make foreach loop parallel (TPL - Parallel.ForEach) or not in such background job or worker? Thank you for explanations.


2 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi Leon,

    Probably it will cause problems since ABP's UnitOfWork is not suitable for such operations. You can try and see it in few trials.

  • User Avatar
    0
    leonkosak created

    Cool. Tnx. :)