Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ABP BackgroundJobs Module - Issue with Processing Jobs Across Multiple Applications #22081

Open
salihozkara opened this issue Feb 5, 2025 · 2 comments

Comments

@salihozkara
Copy link
Member

Problem:

When multiple applications use the ABP BackgroundJobs module and add jobs that are not shared between them, an application may encounter a job that does not belong to it. In such cases, it fails to process the job and marks it as IsAbandoned = true due to a ""Undefined background job for the job name" error. However, this causes the job to never be executed, even though it was never actually processed.

Proposed Solution:

To prevent this issue, filtering can be applied at the IBackgroundJobRepository level so that each application processes only the job types it recognizes. This way, applications will not mistakenly mark jobs as IsAbandoned just because they do not have access to them, preventing unnecessary job losses.

This improvement would ensure more consistent behavior, especially in multi-application scenarios where different applications share the same database but handle separate job processes.

@salihozkara salihozkara added this to the 9.2-preview milestone Feb 5, 2025
@salihozkara salihozkara self-assigned this Feb 5, 2025
@maliming
Copy link
Member

maliming commented Feb 5, 2025

Similar to dynamic permission/feature/setting. We may need a dynamic BackgroundJobs definition system.

@hikalkan
Copy link
Member

hikalkan commented Feb 7, 2025

@maliming that is not similar to dynamic permissions. Here, the job executor is a class with its own code and it can only be executed in the application that has that class definition. So, no way to add a background job in a microservice and then execute it in the administration microservice.

Currently, we don't have a problem in a microservice solution since each microservice has its own database with its own background jobs table and execution queue. Actually, we are already using rabbitmq background job manager (which should also be thought if it has the similar problem @maliming ).

@salihozkara current solution should be using a different database for each application, so they execute only the jobs they queued.

If we want to share the database table between different applications that have different job definitions, then the only way is to add ApplicationName option to the AbpBackgroundJobWorkerOptions class, then use that value on saving and retrieving jobs in that application (so, we also add ApplicationName property to the BackgroundJobInfo class(. The default value can be null for backward compatibility.

Instead of manually setting AbpBackgroundJobWorkerOptions.ApplicationName, we can auto-get from the IApplicationInfoAccessor.ApplicationName by default, so most of the times we don't to set it manually. However, that won't be backward compatible.

So, we can implement like that for the default background job manager. However, we should also consider others (rabbitmq, hangfire), if it is a problem for those applications too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants