|
|
|
@ -177,10 +177,10 @@ public class SysTimerService : ISysTimerService, IDynamicApiController, IScoped
|
|
|
|
|
_sysTimerRep.AsUpdateable(dbTimer).ExecuteCommand();
|
|
|
|
|
|
|
|
|
|
var timer = SpareTime.GetWorkers().ToList().Find(u => u.WorkerName == input.JobName);
|
|
|
|
|
if (timer == null)
|
|
|
|
|
if (timer == null)
|
|
|
|
|
AddTimerJob(input);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 如果 StartNow 为 flase , 执行 AddTimerJob 并不会启动任务
|
|
|
|
|
SpareTime.Start(input.JobName);
|
|
|
|
|
}
|
|
|
|
@ -297,35 +297,45 @@ public class SysTimerService : ISysTimerService, IDynamicApiController, IScoped
|
|
|
|
|
if (taskMethods != null) return taskMethods;
|
|
|
|
|
|
|
|
|
|
// 获取所有本地任务方法,必须有spareTimeAttribute特性
|
|
|
|
|
taskMethods = App.EffectiveTypes
|
|
|
|
|
.Where(u => u.IsClass && !u.IsInterface && !u.IsAbstract && typeof(ISpareTimeWorker).IsAssignableFrom(u))
|
|
|
|
|
.SelectMany(u => u.GetMethods(BindingFlags.Public | BindingFlags.Instance)
|
|
|
|
|
.Where(m => m.IsDefined(typeof(SpareTimeAttribute), false) &&
|
|
|
|
|
m.GetParameters().Length == 2 &&
|
|
|
|
|
m.GetParameters()[0].ParameterType == typeof(SpareTimer) &&
|
|
|
|
|
m.GetParameters()[1].ParameterType == typeof(long) && m.ReturnType == typeof(void))
|
|
|
|
|
.Select(m =>
|
|
|
|
|
{
|
|
|
|
|
// 默认获取第一条任务特性
|
|
|
|
|
var spareTimeAttribute = m.GetCustomAttribute<SpareTimeAttribute>();
|
|
|
|
|
return new TaskMethodInfo
|
|
|
|
|
{
|
|
|
|
|
JobName = spareTimeAttribute.WorkerName,
|
|
|
|
|
RequestUrl = $"{m.DeclaringType.Name}/{m.Name}",
|
|
|
|
|
Cron = spareTimeAttribute.CronExpression,
|
|
|
|
|
DoOnce = spareTimeAttribute.DoOnce,
|
|
|
|
|
ExecuteType = spareTimeAttribute.ExecuteType,
|
|
|
|
|
Interval = (int)spareTimeAttribute.Interval / 1000,
|
|
|
|
|
StartNow = spareTimeAttribute.StartNow,
|
|
|
|
|
RequestType = RequestTypeEnum.Run,
|
|
|
|
|
Remark = spareTimeAttribute.Description,
|
|
|
|
|
TimerType = string.IsNullOrEmpty(spareTimeAttribute.CronExpression) ? SpareTimeTypes.Interval : SpareTimeTypes.Cron,
|
|
|
|
|
MethodName = m.Name,
|
|
|
|
|
DeclaringType = m.DeclaringType
|
|
|
|
|
};
|
|
|
|
|
}));
|
|
|
|
|
taskMethods = App.EffectiveTypes
|
|
|
|
|
.Where(u => u.IsClass && !u.IsInterface && !u.IsAbstract && typeof(ISpareTimeWorker).IsAssignableFrom(u))
|
|
|
|
|
.SelectMany(u => u.GetMethods(BindingFlags.Public | BindingFlags.Instance)
|
|
|
|
|
.Where(m => m.IsDefined(typeof(SpareTimeAttribute), false) &&
|
|
|
|
|
m.GetParameters().Length == 2 &&
|
|
|
|
|
m.GetParameters()[0].ParameterType == typeof(SpareTimer) &&
|
|
|
|
|
m.GetParameters()[1].ParameterType == typeof(long) && m.ReturnType == typeof(void))
|
|
|
|
|
.Select(m =>
|
|
|
|
|
{
|
|
|
|
|
// 默认获取第一条任务特性
|
|
|
|
|
var spareTimeAttribute = m.GetCustomAttribute<SpareTimeAttribute>();
|
|
|
|
|
return new TaskMethodInfo
|
|
|
|
|
{
|
|
|
|
|
JobName = spareTimeAttribute.WorkerName,
|
|
|
|
|
RequestUrl = $"{m.DeclaringType.Name}/{m.Name}",
|
|
|
|
|
Cron = spareTimeAttribute.CronExpression,
|
|
|
|
|
DoOnce = spareTimeAttribute.DoOnce,
|
|
|
|
|
ExecuteType = spareTimeAttribute.ExecuteType,
|
|
|
|
|
Interval = (int)spareTimeAttribute.Interval / 1000,
|
|
|
|
|
StartNow = spareTimeAttribute.StartNow,
|
|
|
|
|
RequestType = RequestTypeEnum.Run,
|
|
|
|
|
Remark = spareTimeAttribute.Description,
|
|
|
|
|
TimerType = string.IsNullOrEmpty(spareTimeAttribute.CronExpression) ? SpareTimeTypes.Interval : SpareTimeTypes.Cron,
|
|
|
|
|
MethodName = m.Name,
|
|
|
|
|
DeclaringType = m.DeclaringType
|
|
|
|
|
};
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
await _cache.SetAsync("TaskMethodInfos", taskMethods);
|
|
|
|
|
return taskMethods;
|
|
|
|
|
}
|
|
|
|
|
//[HttpGet("/BookingOrder/do")]
|
|
|
|
|
//public async Task<bool> Do(long timerId)
|
|
|
|
|
//{
|
|
|
|
|
// var model = await _sysTimerRep.Where(t => t.Id==timerId).Select<JobInput>().FirstAsync();
|
|
|
|
|
// if (model == null) return false;
|
|
|
|
|
// model.StartNow = true;
|
|
|
|
|
// model.Interval = 1;
|
|
|
|
|
// AddTimerJob(model);
|
|
|
|
|
// return true;
|
|
|
|
|
//}
|
|
|
|
|
}
|
|
|
|
|