31 lines
997 B
C#
31 lines
997 B
C#
using Hangfire;
|
|
using Microsoft.Extensions.Configuration;
|
|
using System.Reflection;
|
|
using JiShe.CollectBus.Common.Jobs;
|
|
|
|
// ReSharper disable once CheckNamespace
|
|
namespace Microsoft.Extensions.DependencyInjection
|
|
{
|
|
public static class ServiceCollectionExtensions
|
|
{
|
|
/// <summary>
|
|
/// 添加TcpService服务。
|
|
/// </summary>
|
|
public static IServiceCollection AddJobs(this IServiceCollection services, IConfiguration configuration)
|
|
{
|
|
var interfaceType = typeof(IBaseJob);
|
|
var assembly = Assembly.GetExecutingAssembly();
|
|
|
|
var types = assembly.GetTypes();
|
|
foreach (var type in types)
|
|
{
|
|
if (type.IsClass && type.GetInterfaces().Contains(interfaceType))
|
|
{
|
|
RecurringJob.AddOrUpdate(type.Name, ()=>((type as IBaseJob)!).Execute(), Cron.Minutely, TimeZoneInfo.Utc);
|
|
}
|
|
}
|
|
return services;
|
|
}
|
|
}
|
|
}
|