Open Closed

Add recurring job at run time #4076


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)
  • 0
    maliming created
    Support Team

    hi

    Did you use hangfire or Quartz?

  • 0
    andmattia created

    Hangfire

  • 0
    maliming created
    Support Team

    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

  • 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)
    
    
  • 0
    maliming created
    Support Team

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