Starts in:
0 DAY
17 HRS
32 MIN
56 SEC
Starts in:
0 D
17 H
32 M
56 S
Open Closed

BackgroundJob documentation #1281


User avatar
0
Jurjen created
  • ABP Framework version: v4.3
  • UI type: Blazor
  • DB provider: EF Core
  • Tiered (MVC) or Identity Server Separated (Angular): no

I'm looking into creating some BackgroundJobs. How to create them and how to use the args is pretty straight forward I guess but it's not clear to me in wich (application or module) project the backgroundjobs should be created.

I guess not in the UI, EF or DB-related projects, but could you indicate for application and for module where to create these classes ?

Application
Application.Contracts
Domain
Domain.Shared
HttpApi
HttpApi.Client
{Application}.HttpApi.Host

I have read the documentation and see examples of how to use and enqueue the job but WHERE to create these jobs is not in the documentation. Maybe this could be added to the documentation for future use?

Kind regards, Jurjen.

https://docs.abp.io/en/abp/latest/Background-Jobs https://docs.abp.io/en/abp/latest/Modules/Background-Jobs (= TODO)


7 Answer(s)
  • User Avatar
    0
    gterdem created
    Senior .NET Developer

    I think it depends on your case.

    If you want to use it in your application service only, you can define in .Application layer. If you want to use it in domain events; create in .Domain layer. It's up to which layer you want to choose to be depended on Background Jobs.

    If you check the Module Architecture docs, creating the Background Job in Domain layer makes it available to your whole solution since it will be depended in the core domain.

  • User Avatar
    0
    raif created

    ABP Framework version: v4.3 UI type:MVC DB provider: EF Core Tiered (MVC) or Identity Server Separated (Angular): yes

    Hello, I guess i can use same topic for the question. Unfortunately documentation doesn't mention about how to achieve multi-tenant usage

    Is this background job aware of Tenant ?

    By template default my HOST application capable to execute background jobs. I have a separate database for each of my tenants Tenant may want to execute background job which is need to update tenant's table

    For this purpose i injected ICurrentTenant service to the Job and tenantId parameters to the job arguments

    Is this correct approach

    Second question Is there any possibility to get try count in the job code ?

    public class BackgroundImportOperationUpdateJob : AsyncBackgroundJob<BackgroundImportOperationUpdateArgs>, ITransientDependency
        {
            private IModelManager ModelManager { get; }
            private ICurrentTenant CurrentTenant { get; }
            public BackgroundImportOperationUpdateJob(
                IModelManager modelManager,
                ICurrentTenant currentTenant)
            {
                ModelManager = modelManager;
                CurrentTenant = currentTenant;
            }
         }
    	 
          using (CurrentTenant.Change(args.TenantId))
          {         
                 // Perform operation with domain services in the selected tenant
          }	 
    		 	 
    
  • User Avatar
    0
    raif created

    @gterdem Should i create new topic for my question or is it ok keep at here ? Any feedback about "multi-tenant usage of background jobs' is welcome

    Thx in advance

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi raif

    For this purpose i injected ICurrentTenant service to the Job and tenantId parameters to the job arguments

    This is no problem, the framework will automatically get the tenant's connection string.

    using (CurrentTenant.Change(args.TenantId))
    {
    
    }
    

    Is there any possibility to get try count in the job code ?

    Can you explain why do you want to do this?

  • User Avatar
    0
    raif created

    Is there any possibility to get try count in the job code ?

    Can you explain why do you want to do this?

    According to following explanation https://docs.abp.io/en/abp/4.3/Background-Jobs#exception-handling Background job is automatically re-tried after certain period of time. However i would like to control it with re-try count.

    In a very simple way:

    • Enqueue job after certain act (e.g. entity creation, any certain logic)
    • Try do some operation
    • If you get exception re-try again
    • If everything went well set "some value" to the "A"
    • If you tried X times and if you still get exception then set "some value" to the "B"
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    The call and retry mechanism exists in BackgroundJobWorker, Maybe you can consider override this service, but I don't recommend you to do so.

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

  • User Avatar
    0
    ServiceBot created
    Support Team Automatic process manager

    This question has been automatically marked as stale because it has not had recent activity.

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