Add dedicated workers, parallel execution and successful job retention#25742
Add dedicated workers, parallel execution and successful job retention#25742maliming wants to merge 5 commits into
Conversation
…xecution, job retention)
There was a problem hiding this comment.
Pull request overview
Adds three opt-in enhancements to ABP’s background jobs module (default behavior remains unchanged): retaining successful jobs (via CompletionTime) with periodic cleanup, dedicated workers filtered by job type, and parallel per-job distributed locking for cross-instance execution.
Changes:
- Introduces successful-job retention using
CompletionTimeplus aBackgroundJobCleanupWorkerthat prunes completed jobs based on retention options. - Adds dedicated-worker configuration (
AddDedicatedWorker...) backed by aBackgroundJobWorkerManagerand job-name filtering in stores/repositories. - Implements parallel job execution (
MaxParallelJobExecutionCount) using per-job distributed locks, and adds extensive tests + documentation updates.
Reviewed changes
Copilot reviewed 47 out of 49 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| modules/background-jobs/test/Volo.Abp.BackgroundJobs.TestBase/Volo/Abp/BackgroundJobs/BackgroundJobsTestDataBuilder.cs | Adds additional seeded job to test job-name filtering scenarios. |
| modules/background-jobs/test/Volo.Abp.BackgroundJobs.TestBase/Volo/Abp/BackgroundJobs/BackgroundJobsTestData.cs | Adds a new test job id used by filtering tests. |
| modules/background-jobs/test/Volo.Abp.BackgroundJobs.TestBase/Volo/Abp/BackgroundJobs/BackgroundJobRepository_Tests.cs | Adds repository/store coverage for filtering, completion exclusion, and retention deletion. |
| modules/background-jobs/src/Volo.Abp.BackgroundJobs.MongoDB/Volo/Abp/BackgroundJobs/MongoDB/MongoBackgroundJobRepository.cs | Adds job-name filtering, completion exclusion, and retention delete API for MongoDB. |
| modules/background-jobs/src/Volo.Abp.BackgroundJobs.EntityFrameworkCore/Volo/Abp/BackgroundJobs/EntityFrameworkCore/EfCoreBackgroundJobRepository.cs | Adds job-name filtering, completion exclusion, and retention delete API for EF Core. |
| modules/background-jobs/src/Volo.Abp.BackgroundJobs.EntityFrameworkCore/Volo/Abp/BackgroundJobs/EntityFrameworkCore/BackgroundJobsDbContextModelCreatingExtensions.cs | Adds CompletionTime mapping and updates index to support new queries. |
| modules/background-jobs/src/Volo.Abp.BackgroundJobs.Domain/Volo/Abp/BackgroundJobs/IBackgroundJobRepository.cs | Extends repository contract for filtering and cleanup deletion. |
| modules/background-jobs/src/Volo.Abp.BackgroundJobs.Domain/Volo/Abp/BackgroundJobs/BackgroundJobStore.cs | Extends store API for filtering and cleanup deletion; adjusts FindAsync behavior. |
| modules/background-jobs/src/Volo.Abp.BackgroundJobs.Domain/Volo/Abp/BackgroundJobs/BackgroundJobsDomainMapperlyMappers.cs | Formatting cleanup for mapper namespace/whitespace. |
| modules/background-jobs/src/Volo.Abp.BackgroundJobs.Domain/Volo/Abp/BackgroundJobs/BackgroundJobRecord.cs | Adds CompletionTime to persist successful-job retention state. |
| modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp/Migrations/DemoAppDbContextModelSnapshot.cs | Updates snapshot to include CompletionTime and new index. |
| modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp/Migrations/20260701082002_Added_CompletionTime_To_BackgroundJobs.Designer.cs | Adds EF migration designer for CompletionTime and index changes. |
| modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp/Migrations/20260701082002_Added_CompletionTime_To_BackgroundJobs.cs | Adds EF migration applying CompletionTime column + index changes. |
| modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp/Jobs/SendEmailJob.cs | Adds demo “fast job” used to demonstrate default worker behavior. |
| modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp/Jobs/CalculateAzureFeesJob.cs | Adds demo “slow job” used to demonstrate dedicated worker routing. |
| modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp/Jobs/CalculateAwsFeesJob.cs | Adds demo “slow job” used to demonstrate dedicated worker routing. |
| modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp/DemoAppModule.cs | Demonstrates enabling the new options and enqueuing sample jobs. |
| framework/test/Volo.Abp.BackgroundJobs.Tests/Volo/Abp/BackgroundJobs/WorkerTestJobs.cs | Adds test jobs/args and helpers for parallel + multi-worker validation. |
| framework/test/Volo.Abp.BackgroundJobs.Tests/Volo/Abp/BackgroundJobs/TestableBackgroundJobWorker.cs | Exposes worker internals for unit testing of new behaviors. |
| framework/test/Volo.Abp.BackgroundJobs.Tests/Volo/Abp/BackgroundJobs/TestableBackgroundJobCleanupWorker.cs | Exposes cleanup worker for unit testing. |
| framework/test/Volo.Abp.BackgroundJobs.Tests/Volo/Abp/BackgroundJobs/RecordingBackgroundJobWorker.cs | Adds a recording worker used to assert manager startup behavior. |
| framework/test/Volo.Abp.BackgroundJobs.Tests/Volo/Abp/BackgroundJobs/BackgroundJobWorkerTestBase.cs | Adds shared integrated-test base for worker tests. |
| framework/test/Volo.Abp.BackgroundJobs.Tests/Volo/Abp/BackgroundJobs/BackgroundJobWorker_Tests.cs | Adds tests for retention, filtering, eligibility, and parallel execution. |
| framework/test/Volo.Abp.BackgroundJobs.Tests/Volo/Abp/BackgroundJobs/BackgroundJobWorker_MultiWorkerRegistration_Tests.cs | Verifies manager starts dedicated workers + default worker with correct filters. |
| framework/test/Volo.Abp.BackgroundJobs.Tests/Volo/Abp/BackgroundJobs/BackgroundJobWorker_DuplicateConfiguration_Tests.cs | Ensures invalid multi-worker configurations fail before starting any worker. |
| framework/test/Volo.Abp.BackgroundJobs.Tests/Volo/Abp/BackgroundJobs/BackgroundJobWorker_AutoLockName_Tests.cs | Verifies derived lock-name behavior (stable, bounded length). |
| framework/test/Volo.Abp.BackgroundJobs.Tests/Volo/Abp/BackgroundJobs/BackgroundJobCleanupWorker_Tests.cs | Tests retention cleanup logic and edge cases (e.g., MaxJobFetchCount=0). |
| framework/test/Volo.Abp.BackgroundJobs.Tests/Volo/Abp/BackgroundJobs/AbpSameJobNameTestModule.cs | Test module for “distinct types, same resolved job name” validation. |
| framework/test/Volo.Abp.BackgroundJobs.Tests/Volo/Abp/BackgroundJobs/AbpMultiWorkerTestModule.cs | Test module for multi-worker startup behavior. |
| framework/test/Volo.Abp.BackgroundJobs.Tests/Volo/Abp/BackgroundJobs/AbpDuplicateWorkerTestModule.cs | Test module for duplicate job type across workers validation. |
| framework/test/Volo.Abp.BackgroundJobs.Tests/Volo/Abp/BackgroundJobs/AbpDuplicateLockNameTestModule.cs | Test module for duplicate lock name across workers validation. |
| framework/test/Volo.Abp.BackgroundJobs.Tests/Volo/Abp/BackgroundJobs/AbpBackgroundJobWorkerTestModule.cs | Configures environment for worker tests (manual execution). |
| framework/test/Volo.Abp.BackgroundJobs.Tests/Volo/Abp/BackgroundJobs/AbpBackgroundJobCleanupTestModule.cs | Configures environment for cleanup worker tests. |
| framework/test/Volo.Abp.BackgroundJobs.Tests/Volo/Abp/BackgroundJobs/AbpAutoLockNameWorkerTestModule.cs | Configures environment for derived-lock-name tests. |
| framework/src/Volo.Abp.BackgroundJobs/Volo/Abp/BackgroundJobs/InMemoryBackgroundJobStore.cs | Adds filtering + completion exclusion + retention deletion to in-memory store. |
| framework/src/Volo.Abp.BackgroundJobs/Volo/Abp/BackgroundJobs/IBackgroundJobWorker.cs | Redefines worker contract to support configurable lock/filter start. |
| framework/src/Volo.Abp.BackgroundJobs/Volo/Abp/BackgroundJobs/IBackgroundJobStore.cs | Extends store contract for filtering and retention cleanup deletion. |
| framework/src/Volo.Abp.BackgroundJobs/Volo/Abp/BackgroundJobs/DedicatedWorkerDefinition.cs | Adds validated dedicated-worker definition model for manager startup. |
| framework/src/Volo.Abp.BackgroundJobs/Volo/Abp/BackgroundJobs/BackgroundJobWorkerManager.cs | Introduces manager that validates configurations and starts workers. |
| framework/src/Volo.Abp.BackgroundJobs/Volo/Abp/BackgroundJobs/BackgroundJobWorkerConfiguration.cs | Adds dedicated worker configuration model (lock name + args types). |
| framework/src/Volo.Abp.BackgroundJobs/Volo/Abp/BackgroundJobs/BackgroundJobWorker.cs | Implements configurable workers, filtering, retention on success, and parallel execution. |
| framework/src/Volo.Abp.BackgroundJobs/Volo/Abp/BackgroundJobs/BackgroundJobNameFilterMode.cs | Adds filter mode enum (None/Include/Exclude). |
| framework/src/Volo.Abp.BackgroundJobs/Volo/Abp/BackgroundJobs/BackgroundJobNameFilter.cs | Adds job-name filter model used by workers and stores. |
| framework/src/Volo.Abp.BackgroundJobs/Volo/Abp/BackgroundJobs/BackgroundJobInfo.cs | Adds CompletionTime to represent successful completion retention. |
| framework/src/Volo.Abp.BackgroundJobs/Volo/Abp/BackgroundJobs/BackgroundJobCleanupWorker.cs | Adds worker that deletes completed jobs older than retention. |
| framework/src/Volo.Abp.BackgroundJobs/Volo/Abp/BackgroundJobs/AbpBackgroundJobWorkerOptions.cs | Adds options for retention, dedicated workers, and parallel execution. |
| framework/src/Volo.Abp.BackgroundJobs/Volo/Abp/BackgroundJobs/AbpBackgroundJobsModule.cs | Switches startup to manager + conditional cleanup worker registration. |
| docs/en/modules/background-jobs.md | Links background-jobs module docs to the new framework documentation sections. |
| docs/en/framework/infrastructure/background-jobs/index.md | Documents retention, dedicated workers, and parallel execution options and behavior. |
Files not reviewed (1)
- modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp/Migrations/20260701082002_Added_CompletionTime_To_BackgroundJobs.Designer.cs: Generated file
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 47 out of 49 changed files in this pull request and generated 2 comments.
Files not reviewed (1)
- modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp/Migrations/20260701082002_Added_CompletionTime_To_BackgroundJobs.Designer.cs: Generated file
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## dev #25742 +/- ##
==========================================
+ Coverage 48.86% 49.06% +0.19%
==========================================
Files 3733 3738 +5
Lines 126277 126814 +537
Branches 9709 9750 +41
==========================================
+ Hits 61707 62222 +515
- Misses 62726 62743 +17
- Partials 1844 1849 +5 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 47 out of 49 changed files in this pull request and generated 2 comments.
Files not reviewed (1)
- modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp/Migrations/20260701082002_Added_CompletionTime_To_BackgroundJobs.Designer.cs: Generated file
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 47 out of 49 changed files in this pull request and generated 1 comment.
Files not reviewed (1)
- modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp/Migrations/20260701082002_Added_CompletionTime_To_BackgroundJobs.Designer.cs: Generated file
Resolve #25664
Resolve #25656
Resolve #25606
Three opt-in enhancements to the default background job worker. All are off by default, so existing applications behave exactly as before.
Storing successful jobs (#25664)
By default a job is deleted as soon as it runs successfully. Set
StoreSuccessfulJobs = trueto keep completed jobs in the store instead — a newCompletionTimecolumn marks them. Completed jobs are excluded from the waiting query so they are never run again, and a newBackgroundJobCleanupWorkerprunes them once they are older thanSuccessfulJobRetentionTime(defaults: 7 days retention, cleanup runs hourly viaCleanSuccessfulJobsPeriod; set retention tonullto keep them forever).Dedicated workers per job type (#25656)
AddDedicatedWorker(...)registers a worker that only processes the given job argument types, each with its own distributed lock. A singletonBackgroundJobWorkerManager(following the same pattern as the outbox/inbox sender managers) resolves the workers from DI and starts each one with aBackgroundJobNameFilter; the default worker keeps handling everything not claimed by a dedicated worker. Duplicate job types or lock names are rejected at startup.Parallel job execution (#25606)
Set
MaxParallelJobExecutionCountgreater than 1 to execute multiple jobs per poll cycle. In this mode the single worker-level lock is dropped and each job is instead claimed with its own distributed lock (PerJobDistributedLockPrefix+ job id), so different instances in a cluster can process different jobs at the same time while still never running the same job twice.IBackgroundJobStoreandIBackgroundJobWorkergained the overloads these features need; the EF Core, MongoDB and in-memory stores implement them, and the EF Core index was reordered to serve both the waiting and cleanup queries. Documentation is updated underframework/infrastructure/background-jobs.Integration tests app: https://github.com/maliming/abp-background-jobs-integration-tests