mirror of
https://github.com/fergalmoran/SilkierQuartz.git
synced 2025-12-29 04:57:42 +00:00
add readme
This commit is contained in:
@@ -16,8 +16,11 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
|
|||||||
ProjectSection(SolutionItems) = preProject
|
ProjectSection(SolutionItems) = preProject
|
||||||
.gitattributes = .gitattributes
|
.gitattributes = .gitattributes
|
||||||
.gitignore = .gitignore
|
.gitignore = .gitignore
|
||||||
|
README.md = README.md
|
||||||
EndProjectSection
|
EndProjectSection
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SampleQuartzHostedService", "sample\SampleQuartzHostedService\SampleQuartzHostedService.csproj", "{DE3C9BAF-B262-4346-996C-283E974C0449}"
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
@@ -52,6 +55,18 @@ Global
|
|||||||
{B6BE5ED4-B7F3-48C3-8374-8B479F40F5F2}.Release|x64.Build.0 = Release|Any CPU
|
{B6BE5ED4-B7F3-48C3-8374-8B479F40F5F2}.Release|x64.Build.0 = Release|Any CPU
|
||||||
{B6BE5ED4-B7F3-48C3-8374-8B479F40F5F2}.Release|x86.ActiveCfg = Release|Any CPU
|
{B6BE5ED4-B7F3-48C3-8374-8B479F40F5F2}.Release|x86.ActiveCfg = Release|Any CPU
|
||||||
{B6BE5ED4-B7F3-48C3-8374-8B479F40F5F2}.Release|x86.Build.0 = Release|Any CPU
|
{B6BE5ED4-B7F3-48C3-8374-8B479F40F5F2}.Release|x86.Build.0 = Release|Any CPU
|
||||||
|
{DE3C9BAF-B262-4346-996C-283E974C0449}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{DE3C9BAF-B262-4346-996C-283E974C0449}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{DE3C9BAF-B262-4346-996C-283E974C0449}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||||
|
{DE3C9BAF-B262-4346-996C-283E974C0449}.Debug|x64.Build.0 = Debug|Any CPU
|
||||||
|
{DE3C9BAF-B262-4346-996C-283E974C0449}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||||
|
{DE3C9BAF-B262-4346-996C-283E974C0449}.Debug|x86.Build.0 = Debug|Any CPU
|
||||||
|
{DE3C9BAF-B262-4346-996C-283E974C0449}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{DE3C9BAF-B262-4346-996C-283E974C0449}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{DE3C9BAF-B262-4346-996C-283E974C0449}.Release|x64.ActiveCfg = Release|Any CPU
|
||||||
|
{DE3C9BAF-B262-4346-996C-283E974C0449}.Release|x64.Build.0 = Release|Any CPU
|
||||||
|
{DE3C9BAF-B262-4346-996C-283E974C0449}.Release|x86.ActiveCfg = Release|Any CPU
|
||||||
|
{DE3C9BAF-B262-4346-996C-283E974C0449}.Release|x86.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
@@ -59,6 +74,7 @@ Global
|
|||||||
GlobalSection(NestedProjects) = preSolution
|
GlobalSection(NestedProjects) = preSolution
|
||||||
{08939639-5650-4141-9CC7-9B2956701488} = {DD437750-ADAF-4565-9B50-959A92A67100}
|
{08939639-5650-4141-9CC7-9B2956701488} = {DD437750-ADAF-4565-9B50-959A92A67100}
|
||||||
{B6BE5ED4-B7F3-48C3-8374-8B479F40F5F2} = {EDF98575-67B2-4C80-87FC-051AAF2A9E8A}
|
{B6BE5ED4-B7F3-48C3-8374-8B479F40F5F2} = {EDF98575-67B2-4C80-87FC-051AAF2A9E8A}
|
||||||
|
{DE3C9BAF-B262-4346-996C-283E974C0449} = {B2530695-ADDC-4F87-9B86-E5AEA6FF8EEC}
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||||
SolutionGuid = {C92A5047-9DD9-4F11-9FEE-F1AB1679F94F}
|
SolutionGuid = {C92A5047-9DD9-4F11-9FEE-F1AB1679F94F}
|
||||||
|
|||||||
31
README.md
Normal file
31
README.md
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
# QuartzHostedService
|
||||||
|
|
||||||
|
Wrapper above [Quartz.NET] (https://github.com/quartznet/quartznet) for .NET Core.
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
1. Create Quartz-Job implements IJob interface
|
||||||
|
|
||||||
|
``` C#
|
||||||
|
public class HelloJob : IJob
|
||||||
|
{
|
||||||
|
public Task Execute(IJobExecutionContext context)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Hello");
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
1. Call extension methode __UseQuartzHostedServic__ in *IServiceCollection* and register and configure your created job.
|
||||||
|
``` C#
|
||||||
|
services.UseQuartzHostedService()
|
||||||
|
.RegiserJob<HelloJob>(() =>
|
||||||
|
{
|
||||||
|
var result = new List<TriggerBuilder>();
|
||||||
|
result.Add(TriggerBuilder.Create()
|
||||||
|
.WithSimpleSchedule(x=>x.WithIntervalInSeconds(1).RepeatForever()));
|
||||||
|
result.Add(TriggerBuilder.Create()
|
||||||
|
.WithSimpleSchedule(x => x.WithIntervalInSeconds(2).RepeatForever()));
|
||||||
|
return result;
|
||||||
|
})
|
||||||
|
```
|
||||||
11
sample/SampleQuartzHostedService/InjectProperty.cs
Normal file
11
sample/SampleQuartzHostedService/InjectProperty.cs
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace SampleQuartzHostedService
|
||||||
|
{
|
||||||
|
public class InjectProperty
|
||||||
|
{
|
||||||
|
public string WriteText { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
17
sample/SampleQuartzHostedService/Jobs/HelloJob.cs
Normal file
17
sample/SampleQuartzHostedService/Jobs/HelloJob.cs
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
using Quartz;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace SampleQuartzHostedService.Jobs
|
||||||
|
{
|
||||||
|
public class HelloJob : IJob
|
||||||
|
{
|
||||||
|
public Task Execute(IJobExecutionContext context)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Hello");
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
24
sample/SampleQuartzHostedService/Jobs/InjectSampleJob.cs
Normal file
24
sample/SampleQuartzHostedService/Jobs/InjectSampleJob.cs
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
using Microsoft.Extensions.Options;
|
||||||
|
using Quartz;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace SampleQuartzHostedService.Jobs
|
||||||
|
{
|
||||||
|
public class InjectSampleJob : IJob
|
||||||
|
{
|
||||||
|
InjectProperty _options;
|
||||||
|
|
||||||
|
public InjectSampleJob(IOptions<InjectProperty> options)
|
||||||
|
{
|
||||||
|
_options = options.Value;
|
||||||
|
}
|
||||||
|
public Task Execute(IJobExecutionContext context)
|
||||||
|
{
|
||||||
|
Console.WriteLine(_options.WriteText);
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
44
sample/SampleQuartzHostedService/Program.cs
Normal file
44
sample/SampleQuartzHostedService/Program.cs
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Microsoft.Extensions.Hosting;
|
||||||
|
using Quartz;
|
||||||
|
using QuartzHostedService;
|
||||||
|
using SampleQuartzHostedService.Jobs;
|
||||||
|
using System;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace SampleQuartzHostedService
|
||||||
|
{
|
||||||
|
public class Program
|
||||||
|
{
|
||||||
|
public static async Task Main(string[] args)
|
||||||
|
{
|
||||||
|
var hostBuilder = new HostBuilder()
|
||||||
|
.ConfigureServices(services =>
|
||||||
|
{
|
||||||
|
services.AddOptions();
|
||||||
|
services.Configure<InjectProperty>(options=> { options.WriteText = "This is inject string"; });
|
||||||
|
|
||||||
|
services.UseQuartzHostedService()
|
||||||
|
.RegiserJob<HelloJob>(() =>
|
||||||
|
{
|
||||||
|
var result = new List<TriggerBuilder>();
|
||||||
|
result.Add(TriggerBuilder.Create()
|
||||||
|
.WithSimpleSchedule(x=>x.WithIntervalInSeconds(1).RepeatForever()));
|
||||||
|
result.Add(TriggerBuilder.Create()
|
||||||
|
.WithSimpleSchedule(x => x.WithIntervalInSeconds(2).RepeatForever()));
|
||||||
|
return result;
|
||||||
|
})
|
||||||
|
.RegiserJob<InjectSampleJob>(() =>
|
||||||
|
{
|
||||||
|
var result = new List<TriggerBuilder>();
|
||||||
|
result.Add(TriggerBuilder.Create()
|
||||||
|
.WithSimpleSchedule(x => x.WithIntervalInSeconds(10).RepeatForever()));
|
||||||
|
return result;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
await hostBuilder.RunConsoleAsync();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<OutputType>Exe</OutputType>
|
||||||
|
<TargetFramework>netcoreapp2.1</TargetFramework>
|
||||||
|
<LangVersion>7.1</LangVersion>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Hosting" Version="2.1.1" />
|
||||||
|
<PackageReference Include="Quartz" Version="3.0.6" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\..\src\QuartzHostedService\QuartzHostedService.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
@@ -11,8 +11,13 @@ namespace QuartzHostedService
|
|||||||
{
|
{
|
||||||
public static class IServiceCollectionExtensions
|
public static class IServiceCollectionExtensions
|
||||||
{
|
{
|
||||||
|
public static IJobRegistrator UseQuartzHostedService(this IServiceCollection services)
|
||||||
|
{
|
||||||
|
return UseQuartzHostedService(services, null);
|
||||||
|
}
|
||||||
|
|
||||||
public static IJobRegistrator UseQuartzHostedService(this IServiceCollection services,
|
public static IJobRegistrator UseQuartzHostedService(this IServiceCollection services,
|
||||||
Action<NameValueCollection> stdSchedulerFactoryOptions)
|
Action<NameValueCollection> stdSchedulerFactoryOptions)
|
||||||
{
|
{
|
||||||
services.AddHostedService<QuartzHostedService>();
|
services.AddHostedService<QuartzHostedService>();
|
||||||
|
|
||||||
@@ -23,7 +28,7 @@ namespace QuartzHostedService
|
|||||||
var result = new StdSchedulerFactory();
|
var result = new StdSchedulerFactory();
|
||||||
if (options.Count > 0)
|
if (options.Count > 0)
|
||||||
result.Initialize(options);
|
result.Initialize(options);
|
||||||
return new StdSchedulerFactory();
|
return result;
|
||||||
});
|
});
|
||||||
services.AddTransient<IJobFactory, ServiceCollectionJobFactory>();
|
services.AddTransient<IJobFactory, ServiceCollectionJobFactory>();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user