Skip to content

Commit

Permalink
优化魔方启动
Browse files Browse the repository at this point in the history
  • Loading branch information
nnhy committed Nov 28, 2024
1 parent c0827d3 commit ed4c985
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
5 changes: 2 additions & 3 deletions NewLife.Cube/Services/PageService.cs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
1 change: 1 addition & 0 deletions NewLife.CubeNC/CubeService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
18 changes: 12 additions & 6 deletions NewLife.CubeNC/Services/JobService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,18 @@ public static IServiceCollection AddCubeJob(this IServiceCollection services)
//services.AddSingleton<SqlService>();
//services.AddSingleton<HttpService>();

// 传统建议定时作业,可以不用注册
//services.AddSingleton<BackupDbService>();
BackupDbService.Init();

// 定时作业调度服务
services.AddHostedService<JobService>();

// 扫描并添加ICubeJob作业
Task.Run(JobService.ScanJobs);
_ = Task.Run(() =>
{
// 传统定时作业,可以不用注册
//services.AddSingleton<BackupDbService>();
BackupDbService.Init();

JobService.ScanJobs();
});

return services;
}
Expand Down Expand Up @@ -77,7 +80,7 @@ public Task StopAsync(CancellationToken cancellationToken)
_timer.TryDispose();

// 避免释放过程中集合被修改
_jobs?.ToArray().TryDispose();
_jobs.ToArray().TryDispose();
_jobs.Clear();

return Task.CompletedTask;
Expand Down Expand Up @@ -140,7 +143,10 @@ private void DoJob(Object state)
/// <summary>扫描并添加ICubeJob作业</summary>
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())
{
Expand Down

0 comments on commit ed4c985

Please sign in to comment.