-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWorkerLauncher.cs
More file actions
101 lines (74 loc) · 3.35 KB
/
WorkerLauncher.cs
File metadata and controls
101 lines (74 loc) · 3.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
// using Quartz;
// using System;
// using System.Linq;
// using System.Threading.Tasks;
// using Quartz.Impl;
// using Microsoft.Extensions.Logging;
// using System.Threading;
// using Microsoft.Extensions.DependencyInjection;
// using Microsoft.Extensions.Hosting;
// namespace edok.Common.FolderCleaner.NtService
// {
// public class WorkersLauncher<TJob> : IHostedService where TJob : IJob
// {
// private readonly ILogger _logger;
// private readonly ServiceProviderJobFactory _serviceProviderJobFactory;
// private readonly IHostApplicationLifetime _hostApplicationLifetime;
// private readonly IBuildableJob<TJob> buildableJob;
// private IScheduler _scheduler;
// private IJobDetail _cleaningJob;
// public WorkersLauncher(
// ServiceProviderJobFactory serviceProviderJobFactory,
// IHostApplicationLifetime hostApplicationLifetime,
// ILogger logger,
// IBuildableJob<TJob> buildableJob)
// {
// _hostApplicationLifetime = hostApplicationLifetime ?? throw new ArgumentNullException(nameof(hostApplicationLifetime));
// _logger = logger ?? throw new ArgumentNullException(nameof(logger));
// _serviceProviderJobFactory = serviceProviderJobFactory ?? throw new ArgumentNullException(nameof(serviceProviderJobFactory));
// this.buildableJob = buildableJob ?? throw new ArgumentNullException(nameof(buildableJob));
// }
// public async Task StartAsync(
// CancellationToken cancellationToken)
// {
// try
// {
// _logger.LogInformation($"{GetType().Name} starting...");
// ISchedulerFactory schedFact = new StdSchedulerFactory();
// var namePrefix = GetType().Name;
// var postFix = Guid.NewGuid().ToString().Split("-").First();
// _scheduler = await schedFact.GetScheduler(cancellationToken);
// await _scheduler.Start(CancellationToken.None);
// _scheduler.JobFactory = _serviceProviderJobFactory;
// _cleaningJob = JobBuilder.Create<TJob>().Build();
// var trigger = buildableJob.Create().Build();
// await _scheduler.ScheduleJob(_cleaningJob, trigger, cancellationToken);
// _logger.LogInformation($"{GetType().Name} started.");
// }
// catch (Exception e)
// {
// _logger.LogCritical(e, "Service abnormal start");
// throw;
// }
// }
// public async Task StopAsync(
// CancellationToken cancellationToken)
// {
// try
// {
// _logger.LogInformation($"{GetType().Name} stopping...");
// await _scheduler.Interrupt(_cleaningJob.Key, cancellationToken);
// await _scheduler.Shutdown(true, cancellationToken);
// _logger.LogInformation($"{GetType().Name} stopped");
// }
// catch (Exception e)
// {
// _logger.LogCritical(e, "Service abnormal exit");
// throw;
// }
// }
// }
// }
// public interface IBuildableJob<TJob> where TJob : IJob {
// public JobBuilder Create();
// }