Merge branch 'sqlsugar-dev' into sqlsugar
This commit is contained in:
@@ -22,7 +22,9 @@ Yi框架-一套与SqlSugar一样爽的.Net6低代码开源框架。
|
|||||||
适合.Net6学习、Sqlsugar学习 、项目二次开发。
|
适合.Net6学习、Sqlsugar学习 、项目二次开发。
|
||||||
集大成者,终究轮子
|
集大成者,终究轮子
|
||||||
|
|
||||||
Yi框架最新版本标签:`v1.1.9`,具体版本可以查看标签迭代
|
|
||||||
|
Yi框架最新版本标签:`v1.2.0`,具体版本可以查看标签迭代
|
||||||
|
|
||||||
|
|
||||||
(项目与Sqlsugar同步更新,但这作者老杰哥代码天天爆肝到凌晨两点,我们也尽量会跟上他的脚步。更新频繁,所以可watching持续关注。)
|
(项目与Sqlsugar同步更新,但这作者老杰哥代码天天爆肝到凌晨两点,我们也尽量会跟上他的脚步。更新频繁,所以可watching持续关注。)
|
||||||
|
|
||||||
|
|||||||
@@ -165,7 +165,7 @@ namespace Yi.Framework.ApiMicroservice.Controllers
|
|||||||
{JobConst.method,"get" },
|
{JobConst.method,"get" },
|
||||||
{JobConst.url,"https://www.baidu.com" }
|
{JobConst.url,"https://www.baidu.com" }
|
||||||
};
|
};
|
||||||
await _quartzInvoker.start("*/5 * * * * ?", new Quartz.JobKey("test", "my"), "Yi.Framework.Job", "HttpJob", data: data);
|
await _quartzInvoker.StartAsync("*/5 * * * * ?", "HttpJob",jobName:"test",jobGroup:"my", data: data);
|
||||||
return Result.Success();
|
return Result.Success();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -176,7 +176,7 @@ namespace Yi.Framework.ApiMicroservice.Controllers
|
|||||||
[HttpPut]
|
[HttpPut]
|
||||||
public async Task<Result> stopJob()
|
public async Task<Result> stopJob()
|
||||||
{
|
{
|
||||||
await _quartzInvoker.Stop(new Quartz.JobKey("test", "my"));
|
await _quartzInvoker.StopAsync(new Quartz.JobKey("test", "my"));
|
||||||
return Result.Success();
|
return Result.Success();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,41 +18,33 @@ namespace Yi.Framework.Core
|
|||||||
public delegate T MyAction<T>(CSRedisClient client);
|
public delegate T MyAction<T>(CSRedisClient client);
|
||||||
|
|
||||||
private readonly RedisConnOptions _RedisOptions;
|
private readonly RedisConnOptions _RedisOptions;
|
||||||
|
|
||||||
|
private CSRedisClient Client { get; set; }
|
||||||
|
|
||||||
|
public CSRedisClient _Db { get { return Client; } set { } }
|
||||||
public CacheClientDB(IOptionsMonitor<RedisConnOptions> redisConnOptions)
|
public CacheClientDB(IOptionsMonitor<RedisConnOptions> redisConnOptions)
|
||||||
{
|
{
|
||||||
this._RedisOptions = redisConnOptions.CurrentValue;
|
this._RedisOptions = redisConnOptions.CurrentValue;
|
||||||
|
Client = new CSRedisClient($"{_RedisOptions.Host}:{_RedisOptions.Prot},password={_RedisOptions.Password},defaultDatabase ={ _RedisOptions.DB }");
|
||||||
}
|
}
|
||||||
//public CSRedisClient GetClient()
|
|
||||||
//{
|
|
||||||
// return client;
|
|
||||||
//}
|
|
||||||
//private CSRedisClient client=null;
|
|
||||||
|
|
||||||
// 为了以后全链路做准备
|
|
||||||
|
|
||||||
private T TryCatch<T>(MyAction<T> action)
|
private T TryCatch<T>(MyAction<T> action)
|
||||||
{
|
{
|
||||||
//Stopwatch sw = Stopwatch.StartNew();
|
|
||||||
////Exception ex = null;
|
|
||||||
////bool isError = false;
|
T result = default(T);
|
||||||
var client2 = new CSRedisClient($"{_RedisOptions.Host}:{_RedisOptions.Prot},password={_RedisOptions.Password},defaultDatabase ={ _RedisOptions.DB }");
|
|
||||||
T result;
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
result = action(client2);
|
result = action(Client);
|
||||||
}
|
}
|
||||||
catch (Exception exinfo)
|
catch (Exception exinfo)
|
||||||
{
|
{
|
||||||
object p = null;
|
|
||||||
result = (T)p;
|
|
||||||
//isError = true;
|
|
||||||
Console.WriteLine(exinfo);
|
Console.WriteLine(exinfo);
|
||||||
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
client2.Dispose();
|
|
||||||
}
|
}
|
||||||
|
//finally
|
||||||
|
//{
|
||||||
|
// Client.Dispose();
|
||||||
|
//}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,6 +18,8 @@ namespace Yi.Framework.Core
|
|||||||
private IScheduler _scheduler;
|
private IScheduler _scheduler;
|
||||||
private ILogger<QuartzInvoker> _logger;
|
private ILogger<QuartzInvoker> _logger;
|
||||||
private IJobFactory _jobFactory;
|
private IJobFactory _jobFactory;
|
||||||
|
|
||||||
|
private const string JobDllName = "Yi.Framework.Job";
|
||||||
public QuartzInvoker(ISchedulerFactory schedulerFactory, ILogger<QuartzInvoker> logger, IJobFactory jobFactory)
|
public QuartzInvoker(ISchedulerFactory schedulerFactory, ILogger<QuartzInvoker> logger, IJobFactory jobFactory)
|
||||||
{
|
{
|
||||||
_schedulerFactory = schedulerFactory;
|
_schedulerFactory = schedulerFactory;
|
||||||
@@ -29,27 +31,28 @@ namespace Yi.Framework.Core
|
|||||||
/// 开始任务
|
/// 开始任务
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="cron"></param>
|
/// <param name="cron"></param>
|
||||||
/// <param name="jobKey"></param>
|
|
||||||
/// <param name="jobClass"></param>
|
/// <param name="jobClass"></param>
|
||||||
|
/// <param name="jobName"></param>
|
||||||
|
/// <param name="jobGroup"></param>
|
||||||
/// <param name="second"></param>
|
/// <param name="second"></param>
|
||||||
/// <param name="data"></param>
|
/// <param name="data"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task start(string cron, JobKey jobKey, string dllName,string jobClass, long second = 0, IDictionary<string, object> data = null)
|
public async Task StartAsync(string cron, string jobClass, string jobName = "", string jobGroup = "default", long startAtSecondTime = 0, IDictionary<string, object> data = null)
|
||||||
{
|
{
|
||||||
|
jobName = jobName == "" ? jobClass : jobName;
|
||||||
if (data == null)
|
if (data == null)
|
||||||
{
|
{
|
||||||
data = new Dictionary<string, object>();
|
data = new Dictionary<string, object>();
|
||||||
}
|
}
|
||||||
|
JobKey jobKey = new JobKey(jobName, jobGroup);
|
||||||
var myClass = AssemblyHelper.GetClass(dllName, jobClass).FirstOrDefault();
|
var myClass = AssemblyHelper.GetClass(JobDllName, jobClass).FirstOrDefault();
|
||||||
|
|
||||||
_scheduler = await _schedulerFactory.GetScheduler();
|
_scheduler = await _schedulerFactory.GetScheduler();
|
||||||
_scheduler.JobFactory = _jobFactory;
|
_scheduler.JobFactory = _jobFactory;
|
||||||
//开启调度器
|
|
||||||
await _scheduler.Start();
|
|
||||||
//创建一个触发器
|
//创建一个触发器
|
||||||
var trigger = TriggerBuilder.Create()
|
var trigger = TriggerBuilder.Create()
|
||||||
.StartAt(DateTimeOffset.Now.AddSeconds(second))
|
.StartAt(DateTimeOffset.Now.AddSeconds(startAtSecondTime))
|
||||||
.WithCronSchedule(cron)
|
.WithCronSchedule(cron)
|
||||||
.Build();
|
.Build();
|
||||||
//创建任务
|
//创建任务
|
||||||
@@ -57,18 +60,78 @@ namespace Yi.Framework.Core
|
|||||||
.UsingJobData(new JobDataMap(data))
|
.UsingJobData(new JobDataMap(data))
|
||||||
.WithIdentity(jobKey.Name, jobKey.Group)
|
.WithIdentity(jobKey.Name, jobKey.Group)
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
|
//await _scheduler.AddJob(jobDetail,false);
|
||||||
|
|
||||||
|
//await _scheduler.ScheduleJob(trigger);
|
||||||
//将触发器和任务器绑定到调度器中
|
//将触发器和任务器绑定到调度器中
|
||||||
await _scheduler.ScheduleJob(jobDetail, trigger);
|
await _scheduler.ScheduleJob(jobDetail, trigger);
|
||||||
|
|
||||||
|
//开启调度器
|
||||||
|
await _scheduler.Start();
|
||||||
|
|
||||||
_logger.LogWarning($"开始任务:{jobKey.Name},组别:{jobKey.Group}");
|
_logger.LogWarning($"开始任务:{jobKey.Name},组别:{jobKey.Group}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 开始任务
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="cron"></param>
|
||||||
|
/// <param name="jobClass"></param>
|
||||||
|
/// <param name="jobName"></param>
|
||||||
|
/// <param name="jobGroup"></param>
|
||||||
|
/// <param name="second"></param>
|
||||||
|
/// <param name="data"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task StartAsync(int milliSecondTime, string jobClass, string jobName = "", string jobGroup = "default", long startAtSecondTime = 0, IDictionary<string, object> data = null)
|
||||||
|
{
|
||||||
|
|
||||||
|
jobName = jobName == "" ? jobClass : jobName;
|
||||||
|
|
||||||
|
if (data == null)
|
||||||
|
{
|
||||||
|
data = new Dictionary<string, object>();
|
||||||
|
}
|
||||||
|
JobKey jobKey = new JobKey(jobName, jobGroup);
|
||||||
|
var myClass = AssemblyHelper.GetClass(JobDllName, jobClass).FirstOrDefault();
|
||||||
|
|
||||||
|
_scheduler = await _schedulerFactory.GetScheduler();
|
||||||
|
_scheduler.JobFactory = _jobFactory;
|
||||||
|
|
||||||
|
//创建一个触发器
|
||||||
|
var trigger = TriggerBuilder.Create()
|
||||||
|
.StartAt(DateTimeOffset.Now.AddSeconds(startAtSecondTime))
|
||||||
|
.WithSimpleSchedule(option =>
|
||||||
|
{
|
||||||
|
option.WithInterval(TimeSpan.FromMilliseconds(milliSecondTime)).RepeatForever();
|
||||||
|
})
|
||||||
|
|
||||||
|
.Build();
|
||||||
|
//创建任务
|
||||||
|
var jobDetail = JobBuilder.Create(myClass)
|
||||||
|
.UsingJobData(new JobDataMap(data))
|
||||||
|
.WithIdentity(jobKey.Name, jobKey.Group)
|
||||||
|
.Build();
|
||||||
|
|
||||||
|
//await _scheduler.AddJob(jobDetail,false);
|
||||||
|
|
||||||
|
//await _scheduler.ScheduleJob(trigger);
|
||||||
|
//将触发器和任务器绑定到调度器中
|
||||||
|
await _scheduler.ScheduleJob(jobDetail, trigger);
|
||||||
|
|
||||||
|
//开启调度器
|
||||||
|
await _scheduler.Start();
|
||||||
|
|
||||||
|
_logger.LogWarning($"开始任务:{jobKey.Name},组别:{jobKey.Group}");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 暂停任务
|
/// 暂停任务
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="jobKey"></param>
|
/// <param name="jobKey"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task Stop(JobKey jobKey)
|
public async Task StopAsync(JobKey jobKey)
|
||||||
{
|
{
|
||||||
var _scheduler = await _schedulerFactory.GetScheduler();
|
var _scheduler = await _schedulerFactory.GetScheduler();
|
||||||
//LogUtil.Debug($"暂停任务{jobKey.Group},{jobKey.Name}");
|
//LogUtil.Debug($"暂停任务{jobKey.Group},{jobKey.Name}");
|
||||||
@@ -77,7 +140,7 @@ namespace Yi.Framework.Core
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public async Task Delete(JobKey jobKey)
|
public async Task DeleteAsync(JobKey jobKey)
|
||||||
{
|
{
|
||||||
var _scheduler = await _schedulerFactory.GetScheduler();
|
var _scheduler = await _schedulerFactory.GetScheduler();
|
||||||
//LogUtil.Debug($"暂停任务{jobKey.Group},{jobKey.Name}");
|
//LogUtil.Debug($"暂停任务{jobKey.Group},{jobKey.Name}");
|
||||||
@@ -85,7 +148,7 @@ namespace Yi.Framework.Core
|
|||||||
_logger.LogWarning($"删除任务:{jobKey.Name},组别:{jobKey.Group}");
|
_logger.LogWarning($"删除任务:{jobKey.Name},组别:{jobKey.Group}");
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task Resume(JobKey jobKey)
|
public async Task ResumeAsync(JobKey jobKey)
|
||||||
{
|
{
|
||||||
var _scheduler = await _schedulerFactory.GetScheduler();
|
var _scheduler = await _schedulerFactory.GetScheduler();
|
||||||
//LogUtil.Debug($"恢复任务{jobKey.Group},{jobKey.Name}");
|
//LogUtil.Debug($"恢复任务{jobKey.Group},{jobKey.Name}");
|
||||||
@@ -98,9 +161,9 @@ namespace Yi.Framework.Core
|
|||||||
/// 得到可运行的job列表
|
/// 得到可运行的job列表
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public List<string> getJobClassList()
|
public List<string> GetJobClassList()
|
||||||
{
|
{
|
||||||
var myClassList = AssemblyHelper.GetClass("Yi.Framework.Job");
|
var myClassList = AssemblyHelper.GetClass("ETX.Job");
|
||||||
List<string> data = new List<string>();
|
List<string> data = new List<string>();
|
||||||
myClassList.ForEach(k => data.Add(k.Name));
|
myClassList.ForEach(k => data.Add(k.Name));
|
||||||
return data;
|
return data;
|
||||||
@@ -126,9 +189,9 @@ namespace Yi.Framework.Core
|
|||||||
foreach (ITrigger trigger in triggers)
|
foreach (ITrigger trigger in triggers)
|
||||||
{
|
{
|
||||||
///下一次的执行时间
|
///下一次的执行时间
|
||||||
var utcTime =trigger.GetNextFireTimeUtc();
|
var utcTime = trigger.GetNextFireTimeUtc();
|
||||||
string str = utcTime.ToString();
|
string str = utcTime.ToString();
|
||||||
//TimeZone.CurrentTimeZone.ToLocalTime(Convert.ToDateTime(str));
|
//TimeZone.CurrentTimeZone.ToLocalTime(Convert.ToDateTime(str));
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -142,7 +205,7 @@ namespace Yi.Framework.Core
|
|||||||
|
|
||||||
|
|
||||||
public class JobKeyModel
|
public class JobKeyModel
|
||||||
{
|
{
|
||||||
public JobKey jobKey { get; set; }
|
public JobKey jobKey { get; set; }
|
||||||
public DateTime? nextTime { get; set; }
|
public DateTime? nextTime { get; set; }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -246,7 +246,7 @@ namespace Yi.Framework.Core
|
|||||||
autoAck: false,//不ACK
|
autoAck: false,//不ACK
|
||||||
consumer: consumer);
|
consumer: consumer);
|
||||||
Console.WriteLine($" Register Consumer To {rabbitMQConsumerMode.ExchangeName}-{rabbitMQConsumerMode.QueueName}");
|
Console.WriteLine($" Register Consumer To {rabbitMQConsumerMode.ExchangeName}-{rabbitMQConsumerMode.QueueName}");
|
||||||
Console.ReadLine();
|
//Console.ReadLine();
|
||||||
Console.WriteLine($" After Register Consumer To {rabbitMQConsumerMode.ExchangeName}-{rabbitMQConsumerMode.QueueName}");
|
Console.WriteLine($" After Register Consumer To {rabbitMQConsumerMode.ExchangeName}-{rabbitMQConsumerMode.QueueName}");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ namespace Yi.Framework.WebCore.MiddlewareExtend
|
|||||||
if (Appsettings.appBool("Redis_Enabled"))
|
if (Appsettings.appBool("Redis_Enabled"))
|
||||||
{
|
{
|
||||||
services.Configure<RedisConnOptions>(Appsettings.appConfiguration("RedisConnOptions"));
|
services.Configure<RedisConnOptions>(Appsettings.appConfiguration("RedisConnOptions"));
|
||||||
services.AddTransient<CacheClientDB>();
|
services.AddSingleton<CacheClientDB>();
|
||||||
}
|
}
|
||||||
return services;
|
return services;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user