Advertisement
Guest User

Untitled

a guest
Aug 19th, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. public class Core : ICore
  2. {
  3. private IScheduler scheduler;
  4. private readonly IConfiguration configuration;
  5. private static readonly TimeSpan defaultInterval = new TimeSpan(0,1,0);
  6.  
  7. public Core(IConfiguration configuration)
  8. {
  9. this.configuration = configuration;
  10. }
  11.  
  12. public async Task StartAsync()
  13. {
  14. var interval = configuration.GetValue("interval", defaultInterval);
  15. // Grab the Scheduler instance from the Factory
  16. NameValueCollection props = new NameValueCollection
  17. {
  18. { "quartz.serializer.type", "binary" }
  19. };
  20. StdSchedulerFactory factory = new StdSchedulerFactory(props);
  21. this.scheduler = await factory.GetScheduler();
  22.  
  23. this.scheduler.JobFactory =new SimpleInjectorJobFactory(ContainerWrapper.Container, Assembly.GetExecutingAssembly());
  24.  
  25. IJobDetail job = JobBuilder.Create<RinnovoJob>()
  26. .WithIdentity("RinnovoJob", "sender").StoreDurably(true)
  27. .Build();
  28.  
  29.  
  30.  
  31. ITrigger trigger = TriggerBuilder.Create()
  32. .WithIdentity($"trigger_RinnovoJob", "sender")
  33. .StartNow().WithSimpleSchedule(x=>x.WithInterval(interval))
  34. .Build();
  35.  
  36. // Tell quartz to schedule the job using our trigger
  37. await this.scheduler.ScheduleJob(job, trigger);
  38.  
  39. // and start it off
  40. await this.scheduler.Start();
  41. }
  42.  
  43. public void Dispose()
  44. {
  45.  
  46. }
  47. }
  48.  
  49. public class RinnovoJob:IJob
  50. {
  51. [omiss]
  52.  
  53. public RinnovoJob([omiss])
  54. {
  55. [omiss]
  56. }
  57.  
  58. public Task Execute(IJobExecutionContext context)
  59. {
  60. log.Info("Passed");
  61.  
  62. return Task.CompletedTask;
  63.  
  64. }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement