-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathQuartzScheduler.cs
47 lines (41 loc) · 1.26 KB
/
QuartzScheduler.cs
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
namespace Util.Scheduling;
/// <summary>
/// Quartz调度器
/// </summary>
public class QuartzScheduler : IScheduler {
/// <summary>
/// Quartz调度器
/// </summary>
private readonly Quartz.IScheduler _scheduler;
/// <summary>
/// 初始化Quartz调度器
/// </summary>
/// <param name="scheduler">Quartz调度器</param>
public QuartzScheduler( Quartz.IScheduler scheduler ) {
_scheduler = scheduler ?? throw new ArgumentNullException(nameof(scheduler));
}
/// <inheritdoc />
public async Task StartAsync( CancellationToken cancellationToken = default ) {
if ( _scheduler.IsStarted )
return;
await _scheduler.Start( cancellationToken );
}
/// <summary>
/// 暂停
/// </summary>
public async Task PauseAsync() {
await _scheduler.PauseAll();
}
/// <summary>
/// 恢复
/// </summary>
public async Task ResumeAsync() {
await _scheduler.ResumeAll();
}
/// <inheritdoc />
public async Task StopAsync( CancellationToken cancellationToken = default ) {
if ( _scheduler.IsShutdown )
return;
await _scheduler.Shutdown( true, cancellationToken );
}
}