Open Closed

QuartzBackgroundWorkerBase execute method ran 3 times when Quartz scheduler triggered #118


User avatar
0
talhazengin created

I implemented QuartzBackgroundWorkerBase for my background worker.

The trigger code is this:

Trigger = TriggerBuilder.Create()
    .WithDailyTimeIntervalSchedule(
        builder => builder.StartingDailyAt(TimeOfDay.HourAndMinuteOfDay(X, Y)).EndingDailyAfterCount(1))
    .Build();

Worker triggers the job one time, but Execute method runs 3 times even i used [DisallowConcurrentExecution] attribute for the worker class. I tried many scheduler combinations, but without success.

What can be the problem? It looks like a threading issue. I don't think the problem is with Quartz framework.


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

    I will check this.

  • User Avatar
    0
    talhazengin created

    I am in version 2.4.0.

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi @talhazengin

    I can't reproduce your problem, can you provide more information. If you can use the CLI to create a simple project to reproduce this problem is better :).

  • User Avatar
    0
    talhazengin created

    I am trying to reproduce or fix this. Thanks. I am in version 2.4.0. I will update the framework and check again.

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Did you reproduce the problem? I tested version v2.4, It works fine.

  • User Avatar
    0
    talhazengin created

    Hello @liangshiwei,

    I reproduce the problem in 2.6.2. I have a sample project. How can i share it to you?

    Thanks.

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    liangshiw@outlook.com

    You can send a email to me.

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi @talhazengin

    I checked your code. You added workers repeatedly.

    Quartz integration will automatically add workers, See Source Code. So, for quartz you don't need to add it manually.

    There is another reason for repetition. You did not specify the job identity, for quartz, it is two different jobs.

    In the next version, there will be an option to disable automatic add. See https://github.com/abpframework/abp/pull/3382.

  • User Avatar
    0
    talhazengin created

    Quartz specifies the job identity as GUID itself. So why we need to supply it explicitly?

    You are right, i added extra registiration with below line of code: context.AddBackgroundWorker<MyQuartzWorker>(); When we remove this, repeated registration problem is gone.

    But there is another problem going on: When we start Host project with separated IdentityServer project, now it runs 2 times :( IdentityServer project registers the Quartz again. How is this possible? IdentityServer project includes reference to Domain project, maybe this can cause this.

    Thanks for your helps

  • User Avatar
    0
    talhazengin created

    Ok i found it,

    Below line should be in Host project, should not be in Domain project. [DependsOn(typeof(AbpBackgroundWorkersQuartzModule)

    Thanks.

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    For quartz, it is two different jobs.

    If you want to add only one background worker instance, you should specify Job Identity, See https://www.quartz-scheduler.net/documentation/quartz-3.x/tutorial/index.html for more information.

    But if you use persistent storage, it throws an exception, you can add the following code to your project : https://github.com/liangshiw/AbpVnextQuartzBackground/blob/master/QuartzBackgroundWorkerManager.cs.

    You need to pay attention, if your periodic work is missed multiple times, it will only try to execute it for you once.

    You can track this PR : https://github.com/abpframework/abp/pull/3382.

  • User Avatar
    0
    talhazengin created

    I am not clearly understand the concept of the jobkey and its integration with abp forgive me.

    .WithIdentity(nameof(MyWorker)) is this enough for my case?

                JobDetail = JobBuilder.Create<MyWorker>()
                    .WithIdentity(nameof(MyWorker))
                    .Build();
    
                Trigger = TriggerBuilder.Create()
                    .WithIdentity(nameof(MyWorker))
                    .WithDailyTimeIntervalSchedule(
                        builder => builder.StartingDailyAt(TimeOfDay.HourAndMinuteOfDay(0, 1))
                            .EndingDailyAfterCount(1))
                    .Build();
    
  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Yes this is enough. If you still have problems, I can help you remotely.

  • User Avatar
    0
    talhazengin created

    That's enough for now :) We don't have much time. I am closing this issue, if i need further assistance, i can open a new thread. Thank you.

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