GithubFullScanHostedService.cs 1005 B

1234567891011121314151617181920212223242526272829303132
  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 GithubFullScanHostedService : BackgroundService
  9. {
  10. private readonly GithubScanService githubScanService;
  11. private readonly IOptionsMonitor<GithubOptions> options;
  12. public GithubFullScanHostedService(
  13. GithubScanService 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 githubScanService.ScanAllAsync(stoppingToken);
  24. await Task.Delay(this.options.CurrentValue.ScanAllInterval, stoppingToken);
  25. }
  26. }
  27. }
  28. }