JobBase.cs
1.31 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
using Hh.Mes.Service.Logs;
using Hh.Mes.Service.Repository;
using SqlSugar;
using System;
using System.Threading.Tasks;
namespace Quartz.Job.Jobs
{
/// <summary>
/// 定时器基类
/// 命名空间 Quartz.Job.Jobs 保持一致
/// </summary>
/// <remarks>所有Job实现类应当继承于当前类</remarks>
[PersistJobDataAfterExecution]
[DisallowConcurrentExecution]
public abstract class JobBase : IJob
{
protected readonly QueueJobLog _log = QueueJobLog.GetInstance;
protected readonly ISqlSugarClient _dbContext;
protected JobBase()
{
SysJobRepository sysJobRepository = new SysJobRepository();
_dbContext = sysJobRepository.Context;
}
public virtual Task Execute(IJobExecutionContext context)
{
JobContainer jobContainer = null;
try
{
jobContainer = new JobContainer(context);
ExecuteJob(context);
}
catch (Exception ex)
{
jobContainer.ExceptionInfo = ex.Message;
jobContainer.LoggerJob();
}
jobContainer.UpdateJob();
return Task.CompletedTask;
}
public abstract void ExecuteJob(IJobExecutionContext context);
}
}