-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
增加 任务调度 quartz.net
- Loading branch information
Showing
24 changed files
with
1,027 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using Microsoft.Extensions.Logging; | ||
using Serilog; | ||
using Serilog.Events; | ||
using System; | ||
using System.IO; | ||
|
||
namespace Blog.Core.Common.LogHelper | ||
{ | ||
public class SerilogServer | ||
{ | ||
/// <summary> | ||
/// 记录日常日志 | ||
/// </summary> | ||
/// <param name="filename"></param> | ||
/// <param name="message"></param> | ||
/// <param name="info"></param> | ||
public static void WriteLog(string filename, string message, string info) | ||
{ | ||
Log.Logger = new LoggerConfiguration() | ||
.MinimumLevel.Debug() | ||
.MinimumLevel.Override("Microsoft", LogEventLevel.Error) | ||
.WriteTo.File(Path.Combine($"log/Information/{filename}/", ".txt"), rollingInterval: RollingInterval.Day) | ||
.CreateLogger(); | ||
Log.Information(message+ info, info); | ||
Log.CloseAndFlush(); | ||
} | ||
/// <summary> | ||
/// 记录异常日志 | ||
/// </summary> | ||
/// <param name="filename"></param> | ||
/// <param name="message"></param> | ||
/// <param name="ex"></param> | ||
public static void WriteErrorLog(string filename,string message, Exception ex) | ||
{ | ||
Log.Logger = new LoggerConfiguration() | ||
.MinimumLevel.Debug() | ||
.MinimumLevel.Override("Microsoft", LogEventLevel.Error) | ||
.WriteTo.File(Path.Combine($"log/Error/{filename}/",".txt"),rollingInterval:RollingInterval.Day) | ||
.CreateLogger(); | ||
Log.Error(ex, message); | ||
Log.CloseAndFlush(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
| ||
using Blog.Core.IRepository.Base; | ||
using Blog.Core.Model.Models; | ||
|
||
namespace Blog.Core.IRepository | ||
{ | ||
/// <summary> | ||
/// ITasksQzRepository | ||
/// </summary> | ||
public interface ITasksQzRepository : IBaseRepository<TasksQz> | ||
{ | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
| ||
using Blog.Core.IServices.BASE; | ||
using Blog.Core.Model.Models; | ||
|
||
namespace Blog.Core.IServices | ||
{ | ||
/// <summary> | ||
/// ITasksQzServices | ||
/// </summary> | ||
public interface ITasksQzServices :IBaseServices<TasksQz> | ||
{ | ||
|
||
|
||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
using SqlSugar; | ||
using System; | ||
|
||
namespace Blog.Core.Model.Models | ||
{ | ||
/// <summary> | ||
/// 任务计划表 | ||
/// </summary> | ||
public class TasksQz : RootEntity | ||
{ | ||
/// <summary> | ||
/// 任务名称 | ||
/// </summary> | ||
[SugarColumn(ColumnDataType = "nvarchar", Length = 200, IsNullable = true)] | ||
public string Name { get; set; } | ||
/// <summary> | ||
/// 任务分组 | ||
/// </summary> | ||
[SugarColumn(ColumnDataType = "nvarchar", Length = 200, IsNullable = true)] | ||
public string JobGroup { get; set; } | ||
/// <summary> | ||
/// 任务运行时间表达式 | ||
/// </summary> | ||
[SugarColumn(ColumnDataType = "nvarchar", Length = 200, IsNullable = true)] | ||
public string Cron { get; set; } | ||
/// <summary> | ||
/// 任务所在DLL对应的程序集名称 | ||
/// </summary> | ||
[SugarColumn(ColumnDataType = "nvarchar", Length = 200, IsNullable = true)] | ||
public string AssemblyName { get; set; } | ||
/// <summary> | ||
/// 任务所在类 | ||
/// </summary> | ||
[SugarColumn(ColumnDataType = "nvarchar", Length = 200, IsNullable = true)] | ||
public string ClassName { get; set; } | ||
/// <summary> | ||
/// 任务描述 | ||
/// </summary> | ||
public string Remark { get; set; } | ||
/// <summary> | ||
/// 执行次数 | ||
/// </summary> | ||
public int RunTimes { get; set; } | ||
/// <summary> | ||
/// 开始时间 | ||
/// </summary> | ||
public DateTime? BeginTime { get; set; } | ||
/// <summary> | ||
/// 结束时间 | ||
/// </summary> | ||
public DateTime? EndTime { get; set; } | ||
/// <summary> | ||
/// 触发器类型(0、simple 1、cron) | ||
/// </summary> | ||
public int TriggerType { get; set; } | ||
/// <summary> | ||
/// 执行间隔时间, 秒为单位 | ||
/// </summary> | ||
public int IntervalSecond { get; set; } | ||
/// <summary> | ||
/// 是否启动 | ||
/// </summary> | ||
public bool IsStart { get; set; } = false; | ||
/// <summary> | ||
/// 执行传参 | ||
/// </summary> | ||
public string JobParams { get; set; } | ||
|
||
|
||
[SugarColumn(IsNullable = true)] | ||
public bool? IsDeleted { get; set; } | ||
/// <summary> | ||
/// 创建时间 | ||
/// </summary> | ||
[SugarColumn(IsNullable = true)] | ||
public DateTime CreateTime { get; set; } = DateTime.Now; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
| ||
using Blog.Core.IRepository; | ||
using Blog.Core.IRepository.UnitOfWork; | ||
using Blog.Core.Model.Models; | ||
using Blog.Core.Repository.Base; | ||
|
||
namespace Blog.Core.Repository | ||
{ | ||
/// <summary> | ||
/// TasksQzRepository | ||
/// </summary> | ||
public class TasksQzRepository : BaseRepository<TasksQz>, ITasksQzRepository | ||
{ | ||
public TasksQzRepository(IUnitOfWork unitOfWork) : base(unitOfWork) | ||
{ | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
| ||
using Blog.Core.IRepository; | ||
using Blog.Core.IServices; | ||
using Blog.Core.Model.Models; | ||
using Blog.Core.Services.BASE; | ||
|
||
namespace Blog.Core.Services | ||
{ | ||
public partial class TasksQzServices : BaseServices<TasksQz>, ITasksQzServices | ||
{ | ||
ITasksQzRepository _dal; | ||
public TasksQzServices(ITasksQzRepository dal) | ||
{ | ||
this._dal = dal; | ||
base.BaseDal = dal; | ||
} | ||
|
||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using Blog.Core.Model; | ||
using Blog.Core.Model.Models; | ||
using System.Threading.Tasks; | ||
|
||
namespace Blog.Core.Tasks | ||
{ | ||
/// <summary> | ||
/// 服务调度接口 | ||
/// </summary> | ||
public interface ISchedulerCenter | ||
{ | ||
|
||
/// <summary> | ||
/// 开启任务调度 | ||
/// </summary> | ||
/// <returns></returns> | ||
Task<MessageModel<string>> StartScheduleAsync(); | ||
/// <summary> | ||
/// 停止任务调度 | ||
/// </summary> | ||
/// <returns></returns> | ||
Task<MessageModel<string>> StopScheduleAsync(); | ||
/// <summary> | ||
/// | ||
/// </summary> | ||
/// <param name="sysSchedule"></param> | ||
/// <returns></returns> | ||
Task<MessageModel<string>> AddScheduleJobAsync(TasksQz sysSchedule); | ||
/// <summary> | ||
/// 停止一个任务 | ||
/// </summary> | ||
/// <param name="sysSchedule"></param> | ||
/// <returns></returns> | ||
Task<MessageModel<string>> StopScheduleJobAsync(TasksQz sysSchedule); | ||
/// <summary> | ||
/// 恢复一个任务 | ||
/// </summary> | ||
/// <param name="sysSchedule"></param> | ||
/// <returns></returns> | ||
Task<MessageModel<string>> ResumeJob(TasksQz sysSchedule); | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Quartz; | ||
using Quartz.Spi; | ||
using System; | ||
|
||
namespace Blog.Core.Tasks | ||
{ | ||
public class JobFactory : IJobFactory | ||
{ | ||
/// <summary> | ||
/// 注入反射获取依赖对象 | ||
/// </summary> | ||
private readonly IServiceProvider _serviceProvider; | ||
public JobFactory(IServiceProvider serviceProvider) | ||
{ | ||
_serviceProvider = serviceProvider; | ||
} | ||
/// <summary> | ||
/// 实现接口Job | ||
/// </summary> | ||
/// <param name="bundle"></param> | ||
/// <param name="scheduler"></param> | ||
/// <returns></returns> | ||
public IJob NewJob(TriggerFiredBundle bundle, IScheduler scheduler) | ||
{ | ||
try | ||
{ | ||
var serviceScope = _serviceProvider.CreateScope(); | ||
var job = serviceScope.ServiceProvider.GetService(bundle.JobDetail.JobType) as IJob; | ||
return job; | ||
|
||
} | ||
catch (Exception e) | ||
{ | ||
throw e; | ||
} | ||
} | ||
|
||
public void ReturnJob(IJob job) | ||
{ | ||
var disposable = job as IDisposable; | ||
if (disposable != null) | ||
{ | ||
disposable.Dispose(); | ||
} | ||
|
||
} | ||
} | ||
|
||
} |
Oops, something went wrong.