ArielCore.Jobs 1.0.4

dotnet add package ArielCore.Jobs --version 1.0.4
                    
NuGet\Install-Package ArielCore.Jobs -Version 1.0.4
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="ArielCore.Jobs" Version="1.0.4" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ArielCore.Jobs" Version="1.0.4" />
                    
Directory.Packages.props
<PackageReference Include="ArielCore.Jobs" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add ArielCore.Jobs --version 1.0.4
                    
#r "nuget: ArielCore.Jobs, 1.0.4"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package ArielCore.Jobs@1.0.4
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=ArielCore.Jobs&version=1.0.4
                    
Install as a Cake Addin
#tool nuget:?package=ArielCore.Jobs&version=1.0.4
                    
Install as a Cake Tool

使用步骤:

1.0.3版本使用如下

  1. 首先添加nuget包ArielCore.Jobs
  2. 在Program.cs中的CreateWebHostBuilder后面添加.ConfigureQuartzHost()。并添加MiddleWareBusScheduler.cs文件 如下
  /// <summary>
  /// Quartz中间件
  /// </summary>
  public static class MiddleWareBusScheduler
  {
      /// <summary>
      /// 添加
      /// </summary>
      /// <param name="services"></param>
      /// <param name="configuration"></param>
      public static void AddQuartzJobsService(this IServiceCollection services, IConfiguration configuration)
      {
          services.Configure<QuartzNetOptions>(configuration.GetSection("QuartzNetOptions"));
          //这里可以修改线程数等,如果不需要修改,那么不需要传quartzProperties这个参数
          var quartzProperties = new NameValueCollection
          {
              ["quartz.scheduler.instanceName"] = configuration["quartz:scheduler:instanceName"],
              ["quartz.threadPool.type"] = configuration["quartz:threadPool:type"],
              ["quartz.threadPool.threadPriority"] = configuration["quartz:threadPool:threadPriority"],
              ["quartz.threadPool.threadCount"] = configuration["quartz:threadPool:threadCount"].ToString()
              //["quartz.plugin.jobInitializer.type"] = Plugin?.JobInitializer?.Type,
              //["quartz.plugin.jobInitializer.fileNames"] = Plugin?.JobInitializer?.FileNames
          };
          services.AddQuartzHostedService(quartzProperties)
                  .AddQuartzJob<MyArielJob>("MyArielJob", "ajGp");
      }
      /// <summary>
      /// 启动
      /// </summary>
      /// <param name="app"></param>
      /// <param name="env"></param>
      public static void UserQuartzJobsService(this IApplicationBuilder app, IHostEnvironment env)
      {
          var quartzNetOptions = app.ApplicationServices.GetRequiredService<IOptionsSnapshot<QuartzNetOptions>>();
          var quartzConfigList = quartzNetOptions.Value.QuartzNetConfigs.ToList();
          if (quartzConfigList.FindIndex(x => x.JobName == "MyArielJob" && x.EnableJob) != -1)
          {
              var quartzConfig = quartzNetOptions.Value.QuartzNetConfigs.ToList().Find(x => x.JobName == "MyArielJob");
              var jobCronSchedule = quartzConfig.JobCronSchedule;
              var jobName = quartzConfig.JobName;
              var jobGroup = quartzConfig.JobGroup;
              app.UseQuartzJob<MyArielJob>(env, () =>
              {
                  return TriggerBuilder.Create()
                          .WithIdentity(jobName, jobGroup)
                          .WithCronSchedule(jobCronSchedule);
              });
          }
      }
  }
  1. 在Startup.cs的ConfigureServices方法中加上如下代码(注意需要引用项目ArielCore.Jobs)
  #region Quartz.Net
  services.AddQuartzJobsService(Configuration);
  #endregion

在Startup.cs的Configure方法中加上如下代码,并在方法传参数里面加入 如:

public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IOptionsSnapshot<QuartzNetOptions> quartzNetOptions){}
#region 开启Quartz.Net
app.UserQuartzJobsService(quartzNetOptions);
#endregion
  1. 在appsettings.json文件中添加如下
"QuartzNetOptions": {
  "QuartzNetConfigs": [
    {
      "JobCronSchedule": "0 */5 * * * ?", //每5分钟执行下任务
      "JobName": "MyArielJob",
      "JobGroup": "arGroup",
		"EnableJob": true
    }
  ]
},
"quartz": {
  "scheduler": {
    "instanceName": "HostedService.Quartz"
  },
  "threadPool": {
    "type": "Quartz.Simpl.SimpleThreadPool, Quartz",
    "threadPriority": "Normal",
    "threadCount": 30
  },
  "plugin": {
    "jobInitializer": {
      "type": "Quartz.Plugin.Xml.XMLSchedulingDataProcessorPlugin, Quartz.Plugins",
      "fileNames": "quartz_jobs.xml"
    }
  }
}
  1. 在项目中添加类MyArielJob。注意这个类一定要继承ArielBaseJob。如
  public class MyArielJob : ArielBaseJob
  {
      public MyArielJob()
      {
          Console.Out.WriteLineAsync(DateTime.Now.ToString() + ":构造 Greetings from MyArielJob!");
      }

      public override async Task Execute(IJobExecutionContext context)
      {
          await Console.Out.WriteLineAsync(DateTime.Now.ToString()+ ":Greetings from MyArielJob!");
      }
  }

1.0.3及以上使用

  1. 首先添加nuget包ArielCore.Jobs
  2. 在Program.cs中添加如下配置builder.Host.ConfigureQuartzHost();并添加MiddleWareBusScheduler.cs文件 如下
  using ArielCore.Jobs.QuartzNet;
  using Microsoft.Extensions.Options;
  using Quartz;
  using System.Collections.Specialized;

  /// <summary>
  /// Quartz中间件
  /// </summary>
  public static class MiddleWareBusScheduler
  {
      /// <summary>
      /// 添加
      /// </summary>
      /// <param name="services"></param>
      /// <param name="configuration"></param>
      public static void AddQuartzJobsService(this IServiceCollection services, IConfiguration configuration)
      {
          services.Configure<QuartzNetOptions>(configuration.GetSection("QuartzNetOptions"));
          //这里可以修改线程数等,如果不需要修改,那么不需要传quartzProperties这个参数
          var quartzProperties = new NameValueCollection
          {
              ["quartz.scheduler.instanceName"] = configuration["quartz:scheduler:instanceName"],
              ["quartz.threadPool.type"] = configuration["quartz:threadPool:type"],
              ["quartz.threadPool.threadPriority"] = configuration["quartz:threadPool:threadPriority"],
              ["quartz.threadPool.threadCount"] = configuration["quartz:threadPool:threadCount"].ToString()
              //["quartz.plugin.jobInitializer.type"] = Plugin?.JobInitializer?.Type,
              //["quartz.plugin.jobInitializer.fileNames"] = Plugin?.JobInitializer?.FileNames
          };
          services.AddQuartzHostedService(quartzProperties)
                  .AddQuartzJob<MyArielJob>("MyArielJob", "ajGp");
      }
      /// <summary>
      /// 启动
      /// </summary>
      /// <param name="app"></param>
      /// <param name="env"></param>
      public static void UserQuartzJobsService(this IApplicationBuilder app, IWebHostEnvironment env)
      {
          var quartzNetOptions = app.ApplicationServices.GetRequiredService<IOptionsSnapshot<QuartzNetOptions>>();
          var quartzConfigList = quartzNetOptions.Value.QuartzNetConfigs.ToList();
          if (quartzConfigList.FindIndex(x => x.JobName == "MyArielJob" && x.EnableJob) != -1)
          {
              var quartzConfig = quartzNetOptions.Value.QuartzNetConfigs.ToList().Find(x => x.JobName == "MyArielJob");
              var jobCronSchedule = quartzConfig.JobCronSchedule;
              var jobName = quartzConfig.JobName;
              var jobGroup = quartzConfig.JobGroup;
              app.UseQuartzJob<MyArielJob>(env, () =>
              {
                  return TriggerBuilder.Create()
                          .WithIdentity(jobName, jobGroup)
                          .WithCronSchedule(jobCronSchedule);
              });
          }
      }
  }
  1. 在Program.cs中加上如下代码(注意需要引用项目ArielCore.Jobs)并安装包Microsoft.Extensions.DependencyInjection
  #region Quartz.Net
  builder.Services.AddQuartzJobsService(builder.Configuration);
  #endregion

在Program.cs中加上如下代码,开启Job 如:

  #region 开启Quartz.Net
  app.UserQuartzJobsService(app.Environment);
  app.UseStaticHttpContext();
  #endregion
  1. 在appsettings.json文件中添加如下
"QuartzNetOptions": {
  "QuartzNetConfigs": [
    {
      "JobCronSchedule": "0 */5 * * * ?", //每5分钟执行下任务
      "JobName": "MyArielJob",
      "JobGroup": "arGroup",
		"EnableJob": true
    }
  ]
},
"quartz": {
  "scheduler": {
    "instanceName": "HostedService.Quartz"
  },
  "threadPool": {
    "type": "Quartz.Simpl.SimpleThreadPool, Quartz",
    "threadPriority": "Normal",
    "threadCount": 10
  },
  "plugin": {
    "jobInitializer": {
      "type": "Quartz.Plugin.Xml.XMLSchedulingDataProcessorPlugin, Quartz.Plugins",
      "fileNames": "quartz_jobs.xml"
    }
  }
}
  1. 在项目中添加类MyArielJob。注意这个类一定要继承ArielBaseJob。如
  public class MyArielJob : ArielBaseJob
  {
      public MyArielJob()
      {
          Console.Out.WriteLineAsync(DateTime.Now.ToString() + ":构造 Greetings from MyArielJob!");
      }

      public override async Task Execute(IJobExecutionContext context)
      {
          //实际业务逻辑 
          await Console.Out.WriteLineAsync(DateTime.Now.ToString()+ ":Greetings from MyArielJob!");
      }
  }
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.4 190 12/23/2025
1.0.3 233 5/9/2024
1.0.2 230 10/9/2023