Open Closed

AsyncBackgroundJobs #1628


User avatar
0
Qusai created

Dears,

i tried to Implement backgroundjobs in my solution , i did exactly like the documentation said but still it didn't work.

i want the background job to work on startup knowing that i'm using microservices archetichture.

so can you please tell me how to make it work on startup when i run the microservice its implemented in.


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

    Hi,

    i did exactly like the documentation said but still it didn't work.

    Can you provide steps to reproduce? thanks

  • User Avatar
    0
    Qusai created

    hi,

    i did all whats in this documentation https://docs.abp.io/en/abp/latest/Background-Jobs

    and changed options.IsJobExecutionEnabled to true

    Configure<AbpBackgroundJobOptions>(options => { options.IsJobExecutionEnabled = false; //Disables job execution });

    but still its not working when i run the microservice.

    so i want to know whats the right way to implement it and what to exactly do to make it work on startup.

    and can you also please tell me how it works and what is it usually used for ? just to know if its the right thing for what i need or not

  • User Avatar
    1
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    Can I check it remotely?

  • User Avatar
    0
    Qusai created

    yes , should i send you a zoom link ?

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    Please send an email to me. shiwei.liang@volosoft.com

  • User Avatar
    0
    Qusai created

    the email is not correct

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    HI,

    Sorry, should be shiwei.liang@volosoft.com

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Resolved. You need to queue a job item: https://docs.abp.io/en/abp/latest/Background-Jobs#queue-a-job-item

  • User Avatar
    0
    Qusai created

    one more thing , when we run a backgroundjob how can we determine the Tenant Connectionstring as we are using seperate databases per tenant.

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Use CurrentTenant.Change for per tenant : https://docs.abp.io/en/abp/latest/Multi-Tenancy#change-the-current-tenant

  • User Avatar
    0
    Qusai created

    thanks , also in my background job i use InsertManyAsync , but if the records are more than 10K it does not insert them and it returns TimeOut , and if the records are 10K or less it inserts them but does not return a result.

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    You can try use https://github.com/borisdj/EFCore.BulkExtensions

    I think your main problem has been resolved, so will close the ticket.

  • User Avatar
    0
    Qusai created

    but why InsertManyAsync is not working right ? and EFCore.BulkExtensions only work for Microsoft Sql and SQLLite, i use PostgreSQL.

    and yes my main problem has been resolved but all of these problems are connected, all in the same background job.

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    EFCore.BulkExtensions only work for Microsoft Sql and SQLLite, i use PostgreSQL.

    You can use commercial ef core extension: https://entityframework-extensions.net/bulk-insert, this is actually not related to ABP but EF Core.

    but why InsertManyAsync is not working

    This is no magic, InsertManyAsync just use the native API of EF Core, you will also get the problem without ABP : ) .

  • 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.

  • User Avatar
    0
    Qusai created

    can i do more than one queue for the same job ?

    and the BackGround worker does it execute (DoWorkAsync) everytime the timer starts ? lets say im executing something that will take alot of time and the timer is set to 1 minute , will it still execute the (DoWorkAsync) ? or will it wait until the first execution is done and then count another 1 minute ?

  • User Avatar
    0
    EngincanV created
    Support Team .NET Developer

    Hi @Qusai,

    and the BackGround worker does it execute (DoWorkAsync) everytime the timer starts ? lets say im executing something that will take alot of time and the timer is set to 1 minute , will it still execute the (DoWorkAsync) ? or will it wait until the first execution is done and then count another 1 minute ?

    It waits until the first execution is done but does not count another 1 minute again. For example: Just assume you set your timer as 10 minute and it first called at 1.10pm, and assume your job finished at 1.22pm (took 12minutes, more than our period). The counter will not count from that point it will only count extra 8 minutes to complete your period (10 minutes) and run your worker.

  • User Avatar
    0
    Qusai created

    but for some reason in my case it starts again before it finishes the first execution , i logged everything , and when i check it starts another execution before the first one ends .

  • User Avatar
    0
    Qusai created

    can you please help with the problem i'm having ?

  • User Avatar
    0
    alper created
    Support Team Director

    if you don't want to overlap the jobs, there's a very basic solution; add a static variable bool IsTheLastJobStillRunning = false then check this flag if it's true then return else set this true do your work set this false.

Made with ❤️ on ABP v9.1.0-preview. Updated on November 18, 2024, 05:54