Open Closed

Add recurring job at run time #4076


User avatar
0
andmattia created
  • ABP Framework version: v5.3.1
  • UI type: Angular
  • DB provider: EF Core

HI how can I add a recurring job at run time? and how can I remove it?

so I try to add via startup but I try to read polling intervall via appsettings.json but I can't do it

 public PollingWorker()
    {
        //_options = ServiceProvider.GetService<IOptions<Dataptions>>().Value; --> Null exception
        RecurringJobId = nameof(PollingWorker);
        CronExpression = Cron.MinuteInterval(2);
    }


5 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    Did you use hangfire or Quartz?

  • User Avatar
    0
    andmattia created

    Hangfire

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    how can I add a recurring job at run time? and how can I remove it?

    You can refer to the Hangfire API. https://docs.hangfire.io/en/latest/index.html

    so I try to add via startup but I try to read polling intervall via appsettings.json but I can't do it

    You can try to inject IConfiguration to reading the appsettings

  • User Avatar
    0
    andmattia created

    How can I inject Iconfiguration?

     public override async Task OnApplicationInitializationAsync(
            ApplicationInitializationContext context)
        {
            await context.AddBackgroundWorkerAsync<PollingWorker>();
        }
    

    If I add an IServiceProvider I get this error

    annot resolve parameter 'Microsoft.Extensions.DependencyInjection.IServiceCollection service' of constructor 'Void .ctor(Microsoft.Extensions.DependencyInjection.IServiceCollection)'.
       at Autofac.Core.Activators.Reflection.ReflectionActivator.GetAllBindings(ConstructorBinder[] availableConstructors, IComponentContext context, IEnumerable`1 parameters)
       at Autofac.Core.Activators.Reflection.ReflectionActivator.ActivateInstance(IComponentContext context, IEnumerable`1 parameters)
       at Autofac.Core.Activators.Reflection.ReflectionActivator.<ConfigurePipeline>b__11_0(ResolveRequestContext ctxt, Action`1 next)
       at Autofac.Core.Resolving.Pipeline.ResolvePipelineBuilder.&lt;&gt;c__DisplayClass14_0.&lt;BuildPipeline&gt;b__1(ResolveRequestContext ctxt)
    
    
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    What is your PollingWorker class? You can inject services on the constructor or method context.

Boost Your Development
ABP Live Training
Packages
See Trainings
Mastering ABP Framework Book
Do you need assistance from an ABP expert?
Schedule a Meeting
Mastering ABP Framework Book
The Official Guide
Mastering
ABP Framework
Learn More
Mastering ABP Framework Book
Made with ❤️ on ABP v9.2.0-preview. Updated on March 25, 2025, 11:10