This commit is contained in:
DEVICE8\12494
2023-05-15 14:47:17 +08:00
2 changed files with 16 additions and 3 deletions

View File

@@ -0,0 +1,11 @@
namespace JNPF.TaskScheduler.Listener
{
public class GenerateSpotInspectionPlanTimeWorker : ISpareTimeWorker
{
[SpareTime("0 45 14 * * ? *", "生成点巡检计划", ExecuteType = SpareTimeExecuteTypes.Serial,StartNow = false)]
public void GenerateSpotInspectionPlan(SpareTimer timer, long count)
{
Console.WriteLine("hello world");
}
}
}

View File

@@ -377,14 +377,16 @@ public class TimeTaskService : ITimeTaskService, IDynamicApiController, ITransie
/// <returns></returns>
private async Task<List<TaskMethodInfo>> GetTaskMethods()
{
var taskMethods = await _cacheManager.GetAsync<List<TaskMethodInfo>>(CommonConst.CACHEKEYTIMERJOB);
if (taskMethods != null) return taskMethods;
// var taskMethods = await _cacheManager.GetAsync<List<TaskMethodInfo>>(CommonConst.CACHEKEYTIMERJOB);
// if (taskMethods != null) return taskMethods;
List<TaskMethodInfo> taskMethods = null;
// 获取所有本地任务方法必须有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) &&
.Where(m => m.GetCustomAttributes(typeof(SpareTimeAttribute), false).ToString().Contains("SpareTime") &&
m.GetParameters().Length == 2 &&
m.GetParameters()[0].ParameterType == typeof(SpareTimer) &&
m.GetParameters()[1].ParameterType == typeof(long) && m.ReturnType == typeof(void))