Base solution for your next web application
Open Closed

Background Worker - multiple instances for multiple databases (tenants) #7171


User avatar
0
leonkosak created

Hi,

Based on ABP documentation for Background workers (https://aspnetboilerplate.com/Pages/Documents/Background-Jobs-And-Workers#background-workers), I am wondering how is the most convenient way for running the same worker on all databases (tenant databases)?

  1. Make one instance of background worker and inside worker switching between database contexts (tenant databases) or
  2. Make an instance of background worker for each tenant on application startup and somehow inject tenant to background worker instance?

I have strictly separated databases for each tenant and none is using a host database.

Thank you for explanations.


4 Answer(s)
  • User Avatar
    0
    alper created
    Support Team

    for the sake of code duplication, my choice would be writing one background job and iterate thru tenants.

  • User Avatar
    0
    leonkosak created

    Sorry for late reply.

    https://aspnetboilerplate.com/Pages/Documents/Abp-Session?searchKey=abpsession#overriding-current-session-values

    Is changing tenantId database context also works inside using block?

    using (_session.Use(42, null)) { //correct database context (connection string) for explicitly defined tenantId if this tenant has dedicated database (not using host database)? }

  • User Avatar
    0
    alper created
    Support Team

    using block will overwrite the session.tenantId value in the specified block.

  • User Avatar
    0
    leonkosak created

    including connection string or just tenantid value?