Coder Social home page Coder Social logo

I can not use ISettingManager in QuartzBackgroundWorkerBase,What is the correct way to init Trigger with settingManager info? about abp HOT 3 OPEN

CAH-FlyChen avatar CAH-FlyChen commented on June 20, 2024
I can not use ISettingManager in QuartzBackgroundWorkerBase,What is the correct way to init Trigger with settingManager info?

from abp.

Comments (3)

nebula2 avatar nebula2 commented on June 20, 2024

try getting settings in the task and not in the ctor

from abp.

CAH-FlyChen avatar CAH-FlyChen commented on June 20, 2024

try getting settings in the task and not in the ctor

tried but all fail. for example AsyncHelper , Task ,
I think it's better to have a async methord to init the backgroundworker,not in the constructor.

from abp.

CAH-FlyChen avatar CAH-FlyChen commented on June 20, 2024

solve by strange way
in order to start define settings before worker start, change AutoRegister to false. and start in postapplication event.
in order to execute async methord , config schedule job to flowing

`
public OrderExpCheckerWorker(ISettingManager settingManager, IOrderRepository orderRepository, IServiceProvider serviceProvider) : base()
{
_settingManager = settingManager;
_orderRepository = orderRepository;
_serviceProvider = serviceProvider;

        AutoRegister = false;

        JobDetail = JobBuilder.Create<OrderExpCheckerWorker>().WithIdentity(nameof(OrderExpCheckerWorker)).Build();
        Trigger = TriggerBuilder.Create()
                .WithIdentity(nameof(OrderExpCheckerWorker))
                .Build();
        ScheduleJob = async scheduler =>
        {
            if (!await scheduler.CheckExists(JobDetail.Key))
            {
                var p = await _settingManager.GetOrNullGlobalAsync(EShopConsts.OrderExpireCheckPeriodSetting);
                Trigger = TriggerBuilder.Create()
                .WithIdentity(nameof(OrderExpCheckerWorker))
                .WithSimpleSchedule(s => s.WithIntervalInMinutes(Convert.ToInt32(p))
                                        .RepeatForever()
                                        .WithMisfireHandlingInstructionIgnoreMisfires()
                                    )
                .Build();
                await scheduler.ScheduleJob(JobDetail, Trigger);
            }
        };
    }

`

another way is change Trigger before manual start

from abp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.