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