You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
51 lines
1.4 KiB
51 lines
1.4 KiB
using Quartz; |
|
using System; |
|
using System.Collections.Generic; |
|
using System.Diagnostics; |
|
using System.Linq; |
|
using System.Text; |
|
using System.Threading.Tasks; |
|
|
|
namespace Elight.Logic.Job |
|
{ |
|
[DisallowConcurrentExecution] |
|
public class BaseJob : IJob |
|
{ |
|
|
|
public Stopwatch sw = new Stopwatch(); |
|
public string JobName { get; set; } |
|
public string JobStatus { get; set; } = "任务失败"; |
|
public string JobResult { get; set; } = "*"; |
|
|
|
public BaseJob() |
|
{ |
|
sw.Start(); |
|
} |
|
public virtual Task Execute(IJobExecutionContext context) |
|
{ |
|
return null; |
|
} |
|
|
|
public Task BaseExecute(Action action) |
|
{ |
|
return Task.Run(() => |
|
{ |
|
try |
|
{ |
|
action?.Invoke(); |
|
} |
|
catch (Exception ex) |
|
{ |
|
JobStatus = "任务异常"; |
|
JobResult = ex.StackTrace; |
|
//LogHelper.WriteLogs($"{JobName}:耗时{(sw.ElapsedMilliseconds / 1000)}s", $"{ex.Message}", $"{ex.StackTrace}", true); |
|
} |
|
finally |
|
{ |
|
sw.Stop(); |
|
Console.WriteLine($"{DateTime.Now:yyyy-MM-dd HH:mm} {JobName}:耗时{(sw.ElapsedMilliseconds / 1000)}s-{JobStatus}-{JobResult}", $"{JobStatus}", $"{JobResult}"); |
|
} |
|
}); |
|
} |
|
} |
|
}
|
|
|