From ed4c985deebcfcdc3ad637557bef4117ebc9dc3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=A7=E7=9F=B3=E5=A4=B4?= Date: Thu, 28 Nov 2024 18:07:26 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E9=AD=94=E6=96=B9=E5=90=AF?= =?UTF-8?q?=E5=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- NewLife.Cube/Services/PageService.cs | 5 ++--- NewLife.CubeNC/CubeService.cs | 1 + NewLife.CubeNC/Services/JobService.cs | 18 ++++++++++++------ 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/NewLife.Cube/Services/PageService.cs b/NewLife.Cube/Services/PageService.cs index 5e09af32..beaba5b0 100644 --- a/NewLife.Cube/Services/PageService.cs +++ b/NewLife.Cube/Services/PageService.cs @@ -1,9 +1,8 @@ -using System; -using NewLife.Cube.Modules; +using NewLife.Cube.Modules; +using NewLife.Cube.ViewModels; using NewLife.Reflection; using NewLife.Serialization; using XCode.Membership; -using NewLife.Cube.ViewModels; namespace NewLife.Cube.Services; diff --git a/NewLife.CubeNC/CubeService.cs b/NewLife.CubeNC/CubeService.cs index 3052fbc1..fff1393e 100644 --- a/NewLife.CubeNC/CubeService.cs +++ b/NewLife.CubeNC/CubeService.cs @@ -238,6 +238,7 @@ public static void AddCustomApplicationParts(this IServiceCollection services) manager ??= new ApplicationPartManager(); var list = FindAllArea(); + span?.AppendTag(null, list.Count); foreach (var asm in list) { diff --git a/NewLife.CubeNC/Services/JobService.cs b/NewLife.CubeNC/Services/JobService.cs index 13f1ef68..eb3e66d1 100644 --- a/NewLife.CubeNC/Services/JobService.cs +++ b/NewLife.CubeNC/Services/JobService.cs @@ -23,15 +23,18 @@ public static IServiceCollection AddCubeJob(this IServiceCollection services) //services.AddSingleton(); //services.AddSingleton(); - // 传统建议定时作业,可以不用注册 - //services.AddSingleton(); - BackupDbService.Init(); - // 定时作业调度服务 services.AddHostedService(); // 扫描并添加ICubeJob作业 - Task.Run(JobService.ScanJobs); + _ = Task.Run(() => + { + // 传统定时作业,可以不用注册 + //services.AddSingleton(); + BackupDbService.Init(); + + JobService.ScanJobs(); + }); return services; } @@ -77,7 +80,7 @@ public Task StopAsync(CancellationToken cancellationToken) _timer.TryDispose(); // 避免释放过程中集合被修改 - _jobs?.ToArray().TryDispose(); + _jobs.ToArray().TryDispose(); _jobs.Clear(); return Task.CompletedTask; @@ -140,7 +143,10 @@ private void DoJob(Object state) /// 扫描并添加ICubeJob作业 public static void ScanJobs() { + using var span = DefaultTracer.Instance?.NewSpan(nameof(ScanJobs)); + var jobs = CronJob.FindAll(); + span?.AppendTag(null, jobs.Count); foreach (var type in typeof(ICubeJob).GetAllSubclasses()) {