Open Closed

Abp Background jobs delay and polling system #6768


User avatar
0
mariovh created
  • ABP Framework version: v7.0.0
  • UI Type:Blazor WASM
  • Database System: EF Core (SQL Server)
  • Tiered (for MVC) or Auth Server Separated (for Angular): yes/no
  • Exception message and full stack trace:
  • Steps to reproduce the issue:

Hello,

I'm using AbpBackgroundJobs for tasks that mainly involve generating a PDF certificate, attaching it to an email, and sending it via email through Azure Communication Services in bulk. Around 2000 jobs are queued on average in this operation.

To avoid exceeding the limits of Exchange 365 in email sending (30 emails per minute), I'm queuing the jobs with a 15-second delay between each consecutive one.

During the execution, I've noticed that the 15-second delay isn't always respected, and I've also observed that the execution order of the jobs doesn't strictly follow the NextTryTime. What logic does the polling on the BackgroundJobs table use to select the job to execute?

Here's the scenario: there are 10 jobs with NextTryTime before the current date, and then there are others with NextTryTime after the current date. In what order will they be executed?

If it's not possible to enforce the delay when enqueuing, as job execution times are sometimes less than the planned delay, is it possible to introduce a delay when the job is selected for execution to avoid mailbox saturation?

Finally, with the aim of scaling the application, as it's multi-tenant, is there a possibility for each tenant to have its dedicated background jobs thread independent of other tenants?

Thank you and regards,


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

    Hi,

    The Default BacgkroundJob uses Background worker to execute jobs.

    https://github.com/abpframework/abp/blob/dev/framework/src/Volo.Abp.BackgroundJobs/Volo/Abp/BackgroundJobs/BackgroundJobWorker.cs#L42

    The BackgroundJobWorker default 5 seconds to get jobs waiting to be executed

    https://github.com/abpframework/abp/blob/f8185938d40aaef5fb05de010fc240cf1ec531ee/framework/src/Volo.Abp.BackgroundJobs/Volo/Abp/BackgroundJobs/AbpBackgroundJobWorkerOptions.cs#L9

    ABP provides a simple implementation, you can consider Hangfire integration:

    https://docs.abp.io/en/abp/latest/Background-Jobs-Hangfire

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Finally, with the aim of scaling the application, as it's multi-tenant, is there a possibility for each tenant to have its dedicated background jobs thread independent of other tenants?

    Unfortunately, this cannot be done

Made with ❤️ on ABP v9.1.0-preview. Updated on December 13, 2024, 06:09