我按照这个API来构造Quartz服务:
https://github。com/quartznet/quartznet/blob/main/src/Quartz。Web/Api/SchedulerController。cs
服务缺少“添加调度程序”。我已经尝试为它创建一个API函数如下,但我不知道如何将新的调度程序添加到运行服务。
[HttpPut]
[Route("{schedulerName}/add")]
public async Task Add(string schedulerName)
{
IScheduler scheduler = await GetScheduler(schedulerName).ConfigureAwait(false);
if (scheduler != null)
{
NameValueCollection props = new NameValueCollection();
props.Add("name", schedulerName);
ISchedulerFactory sf = new StdSchedulerFactory(props);
scheduler = sf.GetScheduler().Result;
// TODO services.AddSingleton<IScheduler>(scheduler);
}
}
看看Startup。cs文件,当应用程序启动时,计划服务被添加:
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{...
但是在API控制器中没有对服务的引用。在API中,你可以关闭一个调度程序,但这将从应用程序中删除它。
如何向服务添加新的调度器?