SilkierQuartz.test

This commit is contained in:
MysticBoy
2020-06-06 09:10:10 +08:00
parent 9f21465a28
commit 604571f838
17 changed files with 73 additions and 74 deletions

View File

@@ -1,6 +1,9 @@
MIT License
Copyright (c) 2018 Jan Lucansky
Copyright (c) 2018-2019 Jan Lucansky
Copyright (c) 2019 mukmyash
Copyright (c) 2019-2020 Yanhong Ma
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

View File

@@ -11,6 +11,18 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Quartz.Plugins.RecentHistor
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AspNetCore31", "sample\AspNetCore31\AspNetCore31.csproj", "{98365304-B53D-4A09-91BB-A709BC330511}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{F77F2A7C-C844-4DEE-B797-67AB09655FC1}"
ProjectSection(SolutionItems) = preProject
.dockerignore = .dockerignore
.gitattributes = .gitattributes
.gitignore = .gitignore
.travis.yml = .travis.yml
LICENSE = LICENSE
README.md = README.md
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SilkierQuartz.Test", "test\QuartzHostedService.Test\SilkierQuartz.Test.csproj", "{185EF4D4-EE0C-4365-B465-0D3021949592}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -29,6 +41,10 @@ Global
{98365304-B53D-4A09-91BB-A709BC330511}.Debug|Any CPU.Build.0 = Debug|Any CPU
{98365304-B53D-4A09-91BB-A709BC330511}.Release|Any CPU.ActiveCfg = Release|Any CPU
{98365304-B53D-4A09-91BB-A709BC330511}.Release|Any CPU.Build.0 = Release|Any CPU
{185EF4D4-EE0C-4365-B465-0D3021949592}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{185EF4D4-EE0C-4365-B465-0D3021949592}.Debug|Any CPU.Build.0 = Debug|Any CPU
{185EF4D4-EE0C-4365-B465-0D3021949592}.Release|Any CPU.ActiveCfg = Release|Any CPU
{185EF4D4-EE0C-4365-B465-0D3021949592}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@@ -1,21 +1,23 @@
<p align="center">
<img src="https://raw.githubusercontent.com/jlucansky/public-assets/master/Quartzmin/logo.png" height="150">
</p>
---
[![NuGet](https://img.shields.io/nuget/v/QuartzminFork.svg)](https://www.nuget.org/packages/QuartzminFork)
[![NuGet](https://img.shields.io/nuget/v/SilkierQuartz.svg)](https://www.nuget.org/packages/SilkierQuartz)
[![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](LICENSE)
QuartzminFork is fork from Quartzmin!
Quartzmin is powerful, easy to use web management tool for Quartz.NET
Quartzmin can be used within your existing application with minimum effort as a Quartz.NET plugin when it automatically creates embedded web server. Or it can be plugged into your existing OWIN-based web application as a middleware.
SilkierQuartz is a new after merging [Quartzmin](https://github.com/jlucansky/Quartzmin) and [QuartzHostedService](https://github.com/mukmyash/QuartzHostedService)!
> [Quartz.NET](https://www.quartz-scheduler.net) is a full-featured, open source job scheduling system that can be used from smallest apps to large scale enterprise systems.
> [Quartzmin](https://github.com/jlucansky/Quartzmin) Quartzmin is powerful, easy to use web management tool for Quartz.NET
> [QuartzHostedService](https://github.com/mukmyash/QuartzHostedService) QuartzHostedService is easy to host Quartz as service in .Net Core !
So
SilkierQuartz can be used within your existing application with minimum effort as a Quartz.NET plugin when it automatically creates embedded web server. Or it can be plugged into your existing OWIN-based web application as a middleware.
![Demo](https://raw.githubusercontent.com/jlucansky/public-assets/master/Quartzmin/demo.gif)
The goal of this project is to provide convenient tool to utilize most of the functionality that Quartz.NET enables. The biggest challenge was to create a simple yet effective editor of job data map which is heart of Quartz.NET. Every job data map item is strongly typed and Quartzmin can be easily extended with a custom editor for your specific type beside standard supported types such as String, Integer, DateTime and so on.
@@ -39,51 +41,23 @@ Quartzmin was created with **Semantic UI** and **Handlebars.Net** as the templat
- See recent job history, state and error messages
## Install
Quartzmin is available on [nuget.org](https://www.nuget.org/packages/QuartzminFork)
SilkierQuartz is available on [nuget.org](https://www.nuget.org/packages/SilkierQuartz)
To install QuartzminFork, run the following command in the Package Manager Console
To install SilkierQuartz, run the following command in the Package Manager Console
```powershell
PM> Install-Package QuartzminFork
PM> Install-Package SilkierQuartz
```
## Minimum requirements
- .NET Framework 4.5.2
- .NET Standard 2.0
## Usage
### Embedded web server
Everything you should do is just install [Quartzmin.SelfHost](https://www.nuget.org/packages/Quartzmin.SelfHost) package and configure `QuartzminPlugin` and `ExecutionHistoryPlugin` to support histograms and statistics.
Run the following command in the Package Manager Console:
```powershell
PM> Install-Package Quartzmin.SelfHost
```
Add to your `App.config` file:
```xml
<configuration>
<configSections>
<section name="quartz" type="System.Configuration.NameValueFileSectionHandler" />
</configSections>
<quartz>
<add key="quartz.plugin.quartzmin.type" value="Quartzmin.SelfHost.QuartzminPlugin, Quartzmin.SelfHost" />
<add key="quartz.plugin.quartzmin.url" value="http://localhost:5000" />
<add key="quartz.plugin.recentHistory.type" value="Quartz.Plugins.RecentHistory.ExecutionHistoryPlugin, Quartz.Plugins.RecentHistory" />
<add key="quartz.plugin.recentHistory.storeType" value="Quartz.Plugins.RecentHistory.Impl.InProcExecutionHistoryStore, Quartz.Plugins.RecentHistory" />
</quartz>
</configuration>
```
Start Quartz.NET scheduler somewhere:
```csharp
StdSchedulerFactory.GetDefaultScheduler().Result.Start();
```
- .NET Core 3.1
### OWIN middleware
Add to your `Startup.cs` file:
```csharp
public void Configuration(IAppBuilder app)
{
app.UseQuartzmin(new QuartzminOptions()
app.UseSilkierQuartz(new SilkierQuartzOptions()
{
Scheduler = StdSchedulerFactory.GetDefaultScheduler().Result
});
@@ -95,12 +69,12 @@ Add to your `Startup.cs` file:
```csharp
public void ConfigureServices(IServiceCollection services)
{
services.AddQuartzmin();
services.AddSilkierQuartz();
}
public void Configure(IApplicationBuilder app)
{
app.UseQuartzmin(new QuartzminOptions()
app.UseSilkierQuartz(new QuartzminOptions()
{
Scheduler = StdSchedulerFactory.GetDefaultScheduler().Result
});
@@ -108,7 +82,7 @@ public void Configure(IApplicationBuilder app)
```
## Notes
In clustered environment, it make more sense to host Quarzmin on single dedicated Quartz.NET node in standby mode and implement own `IExecutionHistoryStore` depending on database or ORM framework you typically incorporate. Every clustered Quarz.NET node should be configured with `ExecutionHistoryPlugin` and only dedicated node for management may have `QuartzminPlugin`.
In clustered environment, it make more sense to host SilkierQuartz on single dedicated Quartz.NET node in standby mode and implement own `IExecutionHistoryStore` depending on database or ORM framework you typically incorporate. Every clustered Quarz.NET node should be configured with `ExecutionHistoryPlugin` and only dedicated node for management may have `SilkierQuartzPlugin`.
## License

View File

@@ -1,6 +1,6 @@
using Microsoft.Extensions.DependencyInjection;
namespace Quartzmin
namespace Quartzmin.HostedService
{
public interface IJobRegistrator
{

View File

@@ -9,7 +9,7 @@ using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace Quartzmin
namespace Quartzmin.HostedService
{
public static class IJobRegistratorExtensions
{

View File

@@ -1,7 +1,7 @@
using System.Collections.Generic;
using Quartz;
namespace Quartzmin
namespace Quartzmin.HostedService
{
internal interface IScheduleJob
{

View File

@@ -9,7 +9,7 @@ using System.Collections.Generic;
using System.Collections.Specialized;
using System.Text;
namespace Quartzmin
namespace Quartzmin.HostedService
{
public static class IServiceCollectionExtensions
{

View File

@@ -2,7 +2,7 @@
using System.Collections.Generic;
using System.Text;
namespace Quartzmin
namespace Quartzmin.HostedService
{
public class JobOptions
{

View File

@@ -3,7 +3,7 @@ using System;
using System.Collections.Generic;
using System.Text;
namespace Quartzmin
namespace Quartzmin.HostedService
{
internal class JobRegistrator : IJobRegistrator
{

View File

@@ -10,7 +10,7 @@ using Quartz;
using Quartz.Spi;
using System.Linq;
namespace Quartzmin
namespace Quartzmin.HostedService
{
internal class QuartzHostedService : IHostedService
{

View File

@@ -2,7 +2,7 @@
using System;
using System.Collections.Generic;
namespace Quartzmin
namespace Quartzmin.HostedService
{
internal class ScheduleJob : IScheduleJob
{

View File

@@ -6,7 +6,7 @@ using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Text;
namespace Quartzmin
namespace Quartzmin.HostedService
{
public class ServiceCollectionJobFactory : IJobFactory
{

View File

@@ -3,7 +3,7 @@ using System;
using System.Collections.Generic;
using System.Text;
namespace Quartzmin
namespace Quartzmin.HostedService
{
public class TriggerOptions
{

View File

@@ -0,0 +1,3 @@
using System.Runtime.CompilerServices;
[assembly: InternalsVisibleTo("SilkierQuartz.Test")]

View File

@@ -1,17 +1,19 @@
using FluentAssertions;
using FluentAssertions;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Quartz;
using Quartz.Impl;
using Quartz.Spi;
using Quartzmin;
using Quartzmin.HostedService;
using System;
using Xunit;
namespace QuartzHostedService.Test
namespace SilkierQuartz.Test
{
public class IServiceCollectionExtensionsUnitTest
{
[Fact(DisplayName = "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> HostedService")]
[Fact(DisplayName = "«арегистрировали HostedService")]
public void IServiceCollectionExtensions_Register_HostedService()
{
IServiceCollection serviceCollection = new ServiceCollection();
@@ -20,10 +22,10 @@ namespace QuartzHostedService.Test
var testClass = serviceCollection.BuildServiceProvider().GetRequiredService<IHostedService>();
testClass.Should()
.NotBeNull()
.And.BeOfType<QuartzHostedService>();
.And.BeOfType<Quartzmin.HostedService.QuartzHostedService>();
}
[Fact(DisplayName = "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> IJobFactory (<EFBFBD><EFBFBD><EFBFBD> DI <EFBFBD> Job'<EFBFBD><EFBFBD>)")]
[Fact(DisplayName = "«арегистрировали IJobFactory (дл¤ DI в Job'ах)")]
public void IServiceCollectionExtensions_Register_IJobFactory()
{
IServiceCollection serviceCollection = new ServiceCollection();
@@ -35,7 +37,7 @@ namespace QuartzHostedService.Test
.And.BeOfType<ServiceCollectionJobFactory>();
}
[Fact(DisplayName = "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ISchedulerFactory (<EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>)")]
[Fact(DisplayName = "«арегистрировали ISchedulerFactory (не передали параметры дл¤ инициализации)")]
public void IServiceCollectionExtensions_Register_ISchedulerFactory()
{
IServiceCollection serviceCollection = new ServiceCollection();
@@ -47,20 +49,20 @@ namespace QuartzHostedService.Test
.And.BeOfType<StdSchedulerFactory>();
}
[Fact(DisplayName = "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ISchedulerFactory (<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>)")]
[Fact(DisplayName = "«арегистрировали ISchedulerFactory (передали параметры дл¤ инициализации)")]
public void IServiceCollectionExtensions_Register_ISchedulerFactory_WithParams()
{
IServiceCollection serviceCollection = new ServiceCollection();
IServiceCollectionExtensions.UseQuartzHostedService(serviceCollection, options => { options.Add("quartz.threadPool.threadCount", "1"); });
// TODO: <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// TODO: ѕроверить что параметры передались в конструктор
var testClass = serviceCollection.BuildServiceProvider().GetRequiredService<ISchedulerFactory>();
testClass.Should()
.NotBeNull()
.And.BeOfType<StdSchedulerFactory>();
}
[Fact(DisplayName = "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> IJobRegistrator")]
[Fact(DisplayName = "ѕосле регистрации зависимосте возвращаетс¤ IJobRegistrator")]
public void IServiceCollectionExtensions_Return_IJobRegistrator()
{
IServiceCollection serviceCollection = new ServiceCollection();

View File

@@ -1,4 +1,4 @@
using FakeItEasy;
using FakeItEasy;
using Quartz;
using Quartz.Spi;
using System;
@@ -7,8 +7,8 @@ using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Xunit;
namespace QuartzHostedService.Test
using Quartzmin.HostedService;
namespace SilkierQuartz.Test
{
public class QuartzHostedServiceUnitTest
{

View File

@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.0</TargetFramework>
<TargetFramework>netcoreapp3.1</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>
@@ -20,7 +20,8 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\QuartzHostedService\QuartzHostedService.csproj" />
<ProjectReference Include="..\..\src\Quartz.Plugins.RecentHistory\Quartz.Plugins.RecentHistory.csproj" />
<ProjectReference Include="..\..\src\Quartzmin\Quartzmin.csproj" />
</ItemGroup>
</Project>