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