mirror of
https://github.com/fergalmoran/SilkierQuartz.git
synced 2025-12-22 09:37:56 +00:00
Merge branch 'master' of https://github.com/mukmyash/QuartzHostedService
This commit is contained in:
@@ -35,6 +35,33 @@ namespace QuartzHostedService
|
|||||||
|
|
||||||
return jobRegistrator.RegiserJob<TJob>(triggers());
|
return jobRegistrator.RegiserJob<TJob>(triggers());
|
||||||
}
|
}
|
||||||
|
public static IServiceCollection AddQuartzJobDetail(this IServiceCollection services, Func<IJobDetail> detail)
|
||||||
|
{
|
||||||
|
services.AddSingleton<IScheduleJob>(provider => new ScheduleJob(detail(), new List<ITrigger>()));
|
||||||
|
return services;
|
||||||
|
}
|
||||||
|
public static IServiceCollection AddQuartzJob<TJob>(this IServiceCollection services, string identity) where TJob : class
|
||||||
|
{
|
||||||
|
return services.AddQuartzJob<TJob>(identity, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IServiceCollection AddQuartzJob<TJob>(this IServiceCollection services, string identity, string description) where TJob : class
|
||||||
|
{
|
||||||
|
if (!services.Any(sd => sd.ServiceType == typeof(TJob)))
|
||||||
|
{
|
||||||
|
services.AddTransient<TJob>();
|
||||||
|
}
|
||||||
|
var jobDetail = JobBuilder.Create(typeof(TJob)).WithIdentity(identity).WithDescription(description).Build();
|
||||||
|
services.AddSingleton<IScheduleJob>(provider => new ScheduleJob(jobDetail, new List<ITrigger>()));
|
||||||
|
return services;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static IServiceCollection AddQuartzJobDetail(this IServiceCollection services, IJobDetail detail)
|
||||||
|
{
|
||||||
|
services.AddSingleton<IScheduleJob>(provider => new ScheduleJob(detail, new List<ITrigger>()));
|
||||||
|
return services;
|
||||||
|
}
|
||||||
public static IServiceCollection AddQuartzJob<TJob>(this IServiceCollection services) where TJob : class
|
public static IServiceCollection AddQuartzJob<TJob>(this IServiceCollection services) where TJob : class
|
||||||
{
|
{
|
||||||
services.AddTransient<TJob>();
|
services.AddTransient<TJob>();
|
||||||
@@ -49,6 +76,22 @@ namespace QuartzHostedService
|
|||||||
{
|
{
|
||||||
return app.UseQuartzJob<TJob>(new TriggerBuilder[] { triggerBuilder_func() });
|
return app.UseQuartzJob<TJob>(new TriggerBuilder[] { triggerBuilder_func() });
|
||||||
}
|
}
|
||||||
|
public static IApplicationBuilder UseQuartzJob<TJob>(
|
||||||
|
this IApplicationBuilder app,string JobKey,
|
||||||
|
Func<TriggerBuilder> triggerBuilder_func)
|
||||||
|
where TJob : class, IJob
|
||||||
|
{
|
||||||
|
var _scheduleJobs = app.ApplicationServices.GetService<IEnumerable<IScheduleJob>>();
|
||||||
|
var job = from js in _scheduleJobs where js.JobDetail.JobType == typeof(TJob) && js.JobDetail.Key.Name == JobKey select js;
|
||||||
|
if (job.Any())
|
||||||
|
{
|
||||||
|
var scheduleJob = job.First();
|
||||||
|
var lstgs = (List<ITrigger>)scheduleJob.Triggers;
|
||||||
|
lstgs.Add(triggerBuilder_func().ForJob(scheduleJob.JobDetail).Build());
|
||||||
|
}
|
||||||
|
return app;
|
||||||
|
}
|
||||||
|
|
||||||
public static IApplicationBuilder UseQuartzJob<TJob>(
|
public static IApplicationBuilder UseQuartzJob<TJob>(
|
||||||
this IApplicationBuilder app,
|
this IApplicationBuilder app,
|
||||||
TriggerBuilder triggerBuilder)
|
TriggerBuilder triggerBuilder)
|
||||||
|
|||||||
Reference in New Issue
Block a user