36 lines
1.0 KiB
C#
36 lines
1.0 KiB
C#
|
|
using LangGuan.Services;
|
|||
|
|
using LangGuan.Services.Job;
|
|||
|
|
using Microsoft.Extensions.DependencyInjection;
|
|||
|
|
using Quartz;
|
|||
|
|
using Quartz.Impl;
|
|||
|
|
using System;
|
|||
|
|
using System.Collections.Generic;
|
|||
|
|
using System.Linq;
|
|||
|
|
using System.Threading.Tasks;
|
|||
|
|
|
|||
|
|
namespace LangGuan.Command.Extension
|
|||
|
|
{
|
|||
|
|
public static class LoadJobListExtension
|
|||
|
|
{
|
|||
|
|
public static void AddJobService(this IServiceCollection services)
|
|||
|
|
{
|
|||
|
|
//services.AddSingleton<QuartzUtil>();
|
|||
|
|
services.AddTransient<PlanService>();
|
|||
|
|
Monitor quartz = null;
|
|||
|
|
services.AddSingleton<Monitor>();
|
|||
|
|
quartz = new Monitor(services.BuildServiceProvider());
|
|||
|
|
|
|||
|
|
using (var scope = services.BuildServiceProvider())
|
|||
|
|
{
|
|||
|
|
var myService = scope.GetRequiredService<PlanService>();
|
|||
|
|
var list = myService.GetList().GetAwaiter().GetResult();
|
|||
|
|
if (list.Any())
|
|||
|
|
{
|
|||
|
|
quartz.SetJobs(list);
|
|||
|
|
_ = quartz.StartAsync();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|