GithubResultScanHostedService.cs 1003 B

12345678910111213141516171819202122232425262728293031
  1. using FastGithub.Scanner;
  2. using Microsoft.Extensions.Hosting;
  3. using Microsoft.Extensions.Options;
  4. using System.Threading;
  5. using System.Threading.Tasks;
  6. namespace FastGithub
  7. {
  8. sealed class GithubResultScanHostedService : BackgroundService
  9. {
  10. private readonly IGithubScanService githubScanService;
  11. private readonly IOptionsMonitor<GithubOptions> options;
  12. public GithubResultScanHostedService(
  13. IGithubScanService githubScanService,
  14. IOptionsMonitor<GithubOptions> options)
  15. {
  16. this.githubScanService = githubScanService;
  17. this.options = options;
  18. }
  19. protected override async Task ExecuteAsync(CancellationToken stoppingToken)
  20. {
  21. while (stoppingToken.IsCancellationRequested == false)
  22. {
  23. await Task.Delay(this.options.CurrentValue.ScanResultInterval, stoppingToken);
  24. await githubScanService.ScanResultAsync();
  25. }
  26. }
  27. }
  28. }