Skip to content

Commit

Permalink
Merge pull request #152 from dolunay/master
Browse files Browse the repository at this point in the history
netcore 8 + quartz 3.7.0 + many minor changes
  • Loading branch information
maikebing authored Oct 6, 2024
2 parents 8c26891 + 3cc32ed commit b761014
Show file tree
Hide file tree
Showing 33 changed files with 336 additions and 214 deletions.
20 changes: 20 additions & 0 deletions delete-bin-obj-folders.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
@ECHO off
cls

ECHO Deleting all BIN and OBJ folders...
ECHO.

FOR /d /r . %%d in (bin,obj,LocalNuget) DO (
IF EXIST "%%d" (
ECHO %%d | FIND /I "\node_modules\" > Nul && (
ECHO.Skipping: %%d
) || (
ECHO.Deleting: %%d
rd /s/q "%%d"
)
)
)

ECHO.
ECHO.BIN and OBJ folders have been successfully deleted. Press any key to exit.
pause > nul
6 changes: 3 additions & 3 deletions sample/DemoScheduler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ public static class DemoScheduler
/// How to compatible old code to SilkierQuartz
/// </summary>
/// <param name="app"></param>
public static void SchedulerJobs(this IApplicationBuilder app)
public static void SchedulerJobs(this IApplicationBuilder app)
{
IScheduler scheduler = app.GetScheduler();
var scheduler = app.GetScheduler();
{
var jobData = new JobDataMap();
jobData.Put("DateFrom", DateTime.Now);
Expand Down Expand Up @@ -127,7 +127,7 @@ public static void SchedulerJobs(this IApplicationBuilder app)

}

public class DummyJob : IJob
private class DummyJob : IJob
{
private static readonly Random Random = new Random();

Expand Down
21 changes: 21 additions & 0 deletions sample/Jobs/LongRunningJob.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using Quartz;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;

namespace SilkierQuartz.Example.Jobs
{
public class LongRunningJob : IJob
{
public async Task Execute(IJobExecutionContext context)
{
Console.WriteLine("Long Started");
await Task.Delay(30000);//half min
Console.WriteLine("Long Running");
await Task.Delay(30000);//half min
Console.WriteLine("Long Complete");
await Task.CompletedTask;
}
}
}
2 changes: 1 addition & 1 deletion sample/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public static void Main(string[] args)
CreateHostBuilder(args).Build().Run();
}

public static IHostBuilder CreateHostBuilder(string[] args) =>
private static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
Expand Down
21 changes: 17 additions & 4 deletions sample/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
Expand All @@ -17,7 +18,7 @@ public Startup(IConfiguration configuration)
Configuration = configuration;
}

public IConfiguration Configuration { get; }
private IConfiguration Configuration { get; }

// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
Expand Down Expand Up @@ -59,7 +60,8 @@ public void ConfigureServices(IServiceCollection services)
services.AddQuartzJob<HelloJob>()
.AddQuartzJob<InjectSampleJob>()
.AddQuartzJob<HelloJobSingle>()
.AddQuartzJob<InjectSampleJobSingle>();
.AddQuartzJob<InjectSampleJobSingle>()
.AddQuartzJob<LongRunningJob>();
}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
Expand All @@ -85,11 +87,11 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
endpoints.MapRazorPages();
});
//How to compatible old code to SilkierQuartz
//将旧的原来的规划Job的代码进行移植兼容的示例
//将旧的原来的规划Job的代码进行移植兼容的示例
// app.SchedulerJobs();


#region 不使用 SilkierQuartzAttribe 属性的进行注册和使用的IJob,这里通过UseQuartzJob的IJob必须在 ConfigureServices进行AddQuartzJob
#region 不使用 SilkierQuartzAttribe 属性的进行注册和使用的IJob,这里通过UseQuartzJob的IJob必须在 ConfigureServices进行AddQuartzJob

app.UseQuartzJob<HelloJobSingle>(TriggerBuilder.Create().WithSimpleSchedule(x => x.WithIntervalInSeconds(1).RepeatForever()))
.UseQuartzJob<InjectSampleJobSingle>(() =>
Expand All @@ -108,6 +110,17 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
TriggerBuilder.Create()
.WithCronSchedule("0 0 2 ? * 7 *"),
});
var runAt = DateTime.Now.AddMinutes(3);
app.UseQuartzJob<LongRunningJob>(new List<TriggerBuilder>
{
TriggerBuilder.Create()
.WithSimpleSchedule(x => x.WithIntervalInMinutes(1).RepeatForever()),
TriggerBuilder.Create()
.WithSimpleSchedule(x => x.WithIntervalInMinutes(2).RepeatForever()),
//Add a sample that uses 1-7 for dow
TriggerBuilder.Create()
.WithCronSchedule($"0 {runAt.Minute} {runAt.Hour} ? * {(int)runAt.DayOfWeek} *"),
});

app.UseQuartzJob<InjectSampleJob>(() =>
{
Expand Down
2 changes: 1 addition & 1 deletion sample/example.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFrameworks>net8.0</TargetFrameworks>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
Expand Down
2 changes: 1 addition & 1 deletion sample2/DemoScheduler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public static class DemoScheduler
/// <param name="app"></param>
public static void SchedulerJobs(this IApplicationBuilder app)
{
IScheduler scheduler = app.GetScheduler();
var scheduler = app.GetScheduler();
{
var jobData = new JobDataMap();
jobData.Put("DateFrom", DateTime.Now);
Expand Down
21 changes: 21 additions & 0 deletions sample2/Jobs/LongRunningJob.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using Quartz;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;

namespace SilkierQuartz.Example.Jobs
{
public class LongRunningJob : IJob
{
public async Task Execute(IJobExecutionContext context)
{
Console.WriteLine("Long Started");
await Task.Delay(30000);//half min
Console.WriteLine("Long Running");
await Task.Delay(30000);//half min
Console.WriteLine("Long Complete");
await Task.CompletedTask;
}
}
}
22 changes: 17 additions & 5 deletions sample2/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
builder.Services.AddRazorPages();

var services = builder.Services;
var Configuration =builder.Configuration;
var configuration = builder.Configuration;
services.AddSilkierQuartz(options =>
{
options.VirtualPathRoot = "/quartz";
Expand Down Expand Up @@ -53,12 +53,13 @@
#endif
);
services.AddOptions();
services.Configure<AppSettings>(Configuration);
services.Configure<AppSettings>(configuration);
services.Configure<InjectProperty>(options => { options.WriteText = "This is inject string"; });
services.AddQuartzJob<HelloJob>()
.AddQuartzJob<InjectSampleJob>()
.AddQuartzJob<HelloJobSingle>()
.AddQuartzJob<InjectSampleJobSingle>();
.AddQuartzJob<InjectSampleJobSingle>()
.AddQuartzJob<LongRunningJob>();


var app = builder.Build();
Expand All @@ -84,7 +85,7 @@
app.UseAuthorization();
app.UseSilkierQuartz();
app.MapRazorPages();
#region 不使用 SilkierQuartzAttribe 属性的进行注册和使用的IJob,这里通过UseQuartzJob的IJob必须在 ConfigureServices进行AddQuartzJob
#region 不使用 SilkierQuartzAttribe 属性的进行注册和使用的IJob,这里通过UseQuartzJob的IJob必须在 ConfigureServices进行AddQuartzJob

app.UseQuartzJob<HelloJobSingle>(TriggerBuilder.Create().WithSimpleSchedule(x => x.WithIntervalInSeconds(1).RepeatForever()))
.UseQuartzJob<InjectSampleJobSingle>(() =>
Expand All @@ -103,6 +104,17 @@
TriggerBuilder.Create()
.WithCronSchedule("0 0 2 ? * 7 *"),
});
var runAt = DateTime.Now.AddMinutes(3);
app.UseQuartzJob<LongRunningJob>(new List<TriggerBuilder>
{
TriggerBuilder.Create()
.WithSimpleSchedule(x => x.WithIntervalInMinutes(1).RepeatForever()),
TriggerBuilder.Create()
.WithSimpleSchedule(x => x.WithIntervalInMinutes(2).RepeatForever()),
//Add a sample that uses 1-7 for dow
TriggerBuilder.Create()
.WithCronSchedule($"0 {runAt.Minute} {runAt.Hour} ? * {(int)runAt.DayOfWeek} *"),
});

app.UseQuartzJob<InjectSampleJob>(() =>
{
Expand All @@ -113,4 +125,4 @@
});
#endregion

app.Run();
app.Run();
34 changes: 17 additions & 17 deletions sample2/sample2.csproj
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<UserSecretsId>aspnet-WebApplication1-A527D1EB-9052-4CB4-84DF-96A390FE8CC1</UserSecretsId>
</PropertyGroup>
<PropertyGroup>
<TargetFrameworks>net8.0</TargetFrameworks>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<UserSecretsId>aspnet-WebApplication1-A527D1EB-9052-4CB4-84DF-96A390FE8CC1</UserSecretsId>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="6.0.4" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="6.0.4" />
<PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="6.0.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="6.0.4" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="8.0.8" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="8.0.8" />
<PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="8.0.8" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.8" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.4" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\src\Quartz.Plugins.RecentHistory\Quartz.Plugins.RecentHistory.csproj" />
<ProjectReference Include="..\src\SilkierQuartz\SilkierQuartz.csproj" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\src\Quartz.Plugins.RecentHistory\Quartz.Plugins.RecentHistory.csproj" />
<ProjectReference Include="..\src\SilkierQuartz\SilkierQuartz.csproj" />
</ItemGroup>

</Project>
6 changes: 3 additions & 3 deletions src/Quartz.Plugins.RecentHistory/IExecutionHistoryStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ public class ExecutionHistoryEntry
public string SchedulerName { get; set; }
public string Job { get; set; }
public string Trigger { get; set; }
public DateTime? ScheduledFireTimeUtc { get; set; }
public DateTime ActualFireTimeUtc { get; set; }
public DateTimeOffset? ScheduledFireTimeUtc { get; set; }
public DateTimeOffset ActualFireTimeUtc { get; set; }
public bool Recovering { get; set; }
public bool Vetoed { get; set; }
public DateTime? FinishedTimeUtc { get; set; }
public DateTimeOffset? FinishedTimeUtc { get; set; }
public string ExceptionMessage { get; set; }
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,40 +1,39 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net8.0</TargetFrameworks>
<RestoreProjectStyle>PackageReference</RestoreProjectStyle>
<GeneratePackageOnBuild Condition="'$(Configuration)' == 'Release'">true</GeneratePackageOnBuild>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<NoWarn>1591</NoWarn>

<PropertyGroup>
<TargetFrameworks>net6.0</TargetFrameworks>
<RestoreProjectStyle>PackageReference</RestoreProjectStyle>
<GeneratePackageOnBuild Condition="'$(Configuration)' == 'Release'">true</GeneratePackageOnBuild>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<NoWarn>1591</NoWarn>
<Version>8.0.1</Version>
<Product>SilkierQuartz</Product>
<Title>Quartz.NET plugin to persist recent job execution history</Title>
<Authors>Jan Lucansky,Maikebing</Authors>
<PackageProjectUrl>https://github.com/jlucansky/SilkierQuartz</PackageProjectUrl>
<Description>This is supporting package for SilkierQuartz</Description>
<PackageTags>quartz;recent;history</PackageTags>
<AssemblyVersion>1.0.0.0</AssemblyVersion>
<FileVersion>1.0.0.0</FileVersion>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<Copyright>Copyright © 2018 Jan Lucansky, Copyright © 2020 Maikebing</Copyright>
<RepositoryType>git</RepositoryType>
<RepositoryUrl>https://github.com/jlucansky/SilkierQuartz</RepositoryUrl>
<PackageId>SilkierQuartz.Plugins.RecentHistory</PackageId>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
</PropertyGroup>

<Version>1.0.3</Version>
<Product>SilkierQuartz</Product>
<Title>Quartz.NET plugin to persist recent job execution history</Title>
<Authors>Jan Lucansky,Maikebing</Authors>
<PackageProjectUrl>https://github.com/jlucansky/SilkierQuartz</PackageProjectUrl>
<Description>This is supporting package for SilkierQuartz</Description>
<PackageTags>quartz;recent;history</PackageTags>
<AssemblyVersion>1.0.0.0</AssemblyVersion>
<FileVersion>1.0.0.0</FileVersion>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<Copyright>Copyright © 2018 Jan Lucansky, Copyright © 2020 Maikebing</Copyright>
<RepositoryType>git</RepositoryType>
<RepositoryUrl>https://github.com/jlucansky/SilkierQuartz</RepositoryUrl>
<PackageId>SilkierQuartz.Plugins.RecentHistory</PackageId>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
</PropertyGroup>
<ItemGroup>
<None Include="..\..\.editorconfig" Link=".editorconfig" />
<None Include="..\..\LICENSE" Pack="true" PackagePath="" />
</ItemGroup>

<ItemGroup>
<None Include="..\..\.editorconfig" Link=".editorconfig" />
<None Include="..\..\LICENSE" Pack="true" PackagePath="" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Quartz" Version="3.7.0" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Quartz" Version="3.3.3" />
</ItemGroup>

<ItemGroup>
<None Remove="*.vspscc" />
</ItemGroup>
<ItemGroup>
<None Remove="*.vspscc" />
</ItemGroup>

</Project>
10 changes: 5 additions & 5 deletions src/SilkierQuartz/Controllers/CalendarsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public async Task<IActionResult> Index()

var list = new List<CalendarListItem>();

foreach (string name in calendarNames)
foreach (var name in calendarNames)
{
var cal = await Scheduler.GetCalendar(name);
list.Add(new CalendarListItem() { Name = name, Description = cal.Description, Type = cal.GetType() });
Expand Down Expand Up @@ -73,7 +73,7 @@ public async Task<IActionResult> Save([FromBody] CalendarViewModel[] chain, bool
if (chain.Length == 0 || string.IsNullOrEmpty(chain[0].Name))
result.Errors.Add(ValidationError.EmptyField(nameof(CalendarViewModel.Name)));

for (int i = 0; i < chain.Length; i++)
for (var i = 0; i < chain.Length; i++)
{
RemoveLastEmpty(chain[i].Days);
RemoveLastEmpty(chain[i].Dates);
Expand All @@ -86,17 +86,17 @@ public async Task<IActionResult> Save([FromBody] CalendarViewModel[] chain, bool

if (result.Success)
{
string name = chain[0].Name;
var name = chain[0].Name;

ICalendar existing = null;

if (isNew == false)
existing = await Scheduler.GetCalendar(name);

ICalendar root = null, current = null;
for (int i = 0; i < chain.Length; i++)
for (var i = 0; i < chain.Length; i++)
{
ICalendar newCal = chain[i].Type.Equals("custom") ? existing : chain[i].BuildCalendar();
var newCal = chain[i].Type.Equals("custom") ? existing : chain[i].BuildCalendar();

if (newCal == null)
break;
Expand Down
Loading

0 comments on commit b761014

Please sign in to comment.