Open Closed

Camunda Worker in ABP.io #8001


User avatar
0
Karthigeyan created

Hi Team,

I have integrated Camunda workflow and created a class CamundaWorker which inherits BackgroundService of "Microsoft.Hosting", also added in the context service like below,

context.Services.AddHostedService<CamundaWorker>();

But if I try to call the other application service from CamundaWorker, it is throwing execption "EntityNotFoundException" where the tenant Id is not passed and it is not able to find the entity. How to register the above worker class to the multi-tenany.

Thanks.


1 Answer(s)
  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    How to register the above worker class to the multi-tenany.

    You need to get all tenants first. You can try to use ADO.NET to get all tenants and register workers class to the multi-tenany

    SqlConnection connection = new(connectionString);
    
    var tenants = await connection....;
    
    foreach(var tenant in tenants)
    {
        context.Services.AddHostedService....
    }
    

    But there is a problem, When you add a new tenant, you need to restart the application.

    I recommend you to loop through all tenants in the worker

    public class CamundaWorker ....
    {
         public ......()
         {
             var tenants = await TenantRepository.GetListAsync();
             
             foreach(var tenant in tenants)
             {
                 using(CurrentTenant.Change(tenant.Id))
                 {
                      ... 
                 }
             }
         }
    }
    
Made with ❤️ on ABP v9.1.0-preview. Updated on November 01, 2024, 05:35