AddJobsExtention.cs 876 B

1234567891011121314151617181920212223242526272829
  1. using Quartz;
  2. namespace EVCB_OCPP.DBAPI.Jobs
  3. {
  4. public static class AddJobsExtention
  5. {
  6. public static IServiceCollection AddJobs(this IServiceCollection services)
  7. {
  8. services.AddQuartz(q =>
  9. {
  10. q.UseMicrosoftDependencyInjectionJobFactory();
  11. q.ScheduleJob<ServerMessageJob>(trigger =>
  12. trigger
  13. .WithIdentity("ServerMessageJobTrigger")
  14. .StartNow()
  15. .WithSimpleSchedule(x => x
  16. .WithInterval(TimeSpan.FromSeconds(10))
  17. .RepeatForever())
  18. );
  19. });
  20. services.AddQuartzHostedService(opt =>
  21. {
  22. opt.WaitForJobsToComplete = true;
  23. });
  24. return services;
  25. }
  26. }
  27. }