RZ.Quartz.SqlServer 6.0.1

dotnet add package RZ.Quartz.SqlServer --version 6.0.1
                    
NuGet\Install-Package RZ.Quartz.SqlServer -Version 6.0.1
                    
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="RZ.Quartz.SqlServer" Version="6.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="RZ.Quartz.SqlServer" Version="6.0.1" />
                    
Directory.Packages.props
<PackageReference Include="RZ.Quartz.SqlServer" />
                    
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 RZ.Quartz.SqlServer --version 6.0.1
                    
#r "nuget: RZ.Quartz.SqlServer, 6.0.1"
                    
#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 RZ.Quartz.SqlServer@6.0.1
                    
#: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=RZ.Quartz.SqlServer&version=6.0.1
                    
Install as a Cake Addin
#tool nuget:?package=RZ.Quartz.SqlServer&version=6.0.1
                    
Install as a Cake Tool

RZ.Quartz 项目说明

简介

RZ.Quartz 是一个基于 Quartz 的任务调度框架封装,旨在简化在 .NET 项目中使用定时任务的流程。它支持通过 HTTP 请求触发任务,并提供对 MySQL 和 SQL Server 的数据库配置支持。

该项目适合希望快速集成定时任务调度功能的开发者,且支持通过简单的 API 管理任务的创建、暂停、恢复和删除。

特性

  • 支持通过 HTTP 请求执行定时任务
  • 提供任务的动态管理:添加、更新、暂停、恢复和删除
  • 支持多种数据库类型(MySQL、SQL Server)进行任务存储
  • 支持 Cron 表达式配置定时任务
  • 简单易用的 API 控制器进行任务管理
  • 支持任务并发控制和错误处理

安装与配置

1. 项目结构

  • src/RZ.Quartz: 核心库代码,包含 Quartz 的封装逻辑
  • src/RZ.Quartz.MySqlsrc/RZ.Quartz.SqlServer: 分别用于 MySQL 和 SQL Server 的数据库支持
  • demo/WebApp.Quartz: 示例 Web 应用,展示如何使用 RZ.Quartz

2. 配置数据库支持

QuarztOptions 中,可以使用以下方法设置数据库:

options.SetSqlServer("your_sqlserver_connection_string");
options.SetMySql("your_mysql_connection_string");

3. 配置 Cron 表达式

通过 RZCronAttribute 特性为任务设置 Cron 表达式,如:

[RZCron("0/1 * * * * ?")]
public class QuarztTask : IRZJob

使用示例

创建一个定时任务

[RZCron("0/1 * * * * ?")]
public class QuarztTask : IRZJob
{
    private readonly ILogger<QuarztTask> _logger;

    public QuarztTask(ILogger<QuarztTask> logger) => _logger = logger;

    public async Task Execute(IJobExecutionContext context)
    {
        _logger.LogInformation("定时任务执行中");
    }
}

使用 API 管理任务

QuarztController 提供了 RESTful API,可以执行以下操作:

  • 获取所有任务列表
  • 暂停和恢复任务
  • 更新任务的 Cron 表达式
  • 手动触发任务
  • 添加或更新 HTTP 任务

示例:添加一个 HTTP 任务

POST /quarzt/addorupdate/httpjob
{
    "JobName": "HttpJob",
    "Url": "http://example.com/api/endpoint",
    "Method": "POST",
    "Cron": "0/1 * * * * ?"
}

禁用任务

通过 RZDisableJobAttribute 可以禁用特定任务:

[RZDisableJob]
public class DisableJobTask : IRZJob

API 文档

获取所有任务

GET /quarzt/get/all/jobs

暂停任务

PUT /quarzt/pause/job?jobName=JobName

恢复任务

PUT /quarzt/resume/job?jobName=JobName

更新任务 Cron

PUT /quarzt/update/cron?jobName=JobName&newCron=0/10 * * * * ?

删除任务

DELETE /quarzt/delete/job?jobName=JobName

手动触发任务

POST /quarzt/manualtrigger/job?jobName=JobName

添加/更新 HTTP 任务

POST /quarzt/addorupdate/httpjob
{
    "JobName": "MyHttpJob",
    "Url": "http://your-endpoint.com",
    "Method": "GET",
    "Cron": "0/5 * * * * ?"
}

贡献指南

欢迎提交 Issue 和 Pull Request。请确保代码风格与现有代码一致,并提供完整的单元测试。

许可证

本项目采用 MIT 许可证。详情请参阅 LICENSE 文件。

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  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
6.0.1 333 11/12/2025
6.0.0 328 11/12/2025