...
 
Commits (3)
    https://gitcode.net/int/quartznet/-/commit/21752a6fc153fee8d7dc75c5cda33a8f0f5ca145 Remove references to UseMicrosoftDependencyInjection* methods in microsoft-di... 2023-08-14T18:45:50+03:00 Marko Lahma marko.lahma@gmail.com https://gitcode.net/int/quartznet/-/commit/1820834b72135dee00f48a1e88af10b663b6e9f7 DailyCalendar should use same time zone offset for all checks (#2113) 2023-08-18T19:38:22+03:00 Kevin Petit kevin.petit@outlook.com Co-authored-by: <span data-trailer="Co-authored-by:"><a href="mailto:kevin.petit@hacksis.dev" title="kevin.petit@hacksis.dev"></a><a href="javascript:void(0)" class="avatar s16 avatar-inline identicon bg2" style="text-decoration: none">N</a><a href="mailto:kevin.petit@hacksis.dev" title="kevin.petit@hacksis.dev">Kevin Petit</a> &lt;<a href="mailto:kevin.petit@hacksis.dev" title="kevin.petit@hacksis.dev">kevin.petit@hacksis.dev</a>&gt;</span> https://gitcode.net/int/quartznet/-/commit/859911dbbb9b8b9286fe1dcadc05849cf72fed8b Remove leftover Quartz.Extensions.Hosting contents 2023-08-18T19:49:11+03:00 Marko Lahma marko.lahma@gmail.com
......@@ -94,16 +94,10 @@ public void ConfigureServices(IServiceCollection services)
{
// handy when part of cluster or you want to otherwise identify multiple schedulers
q.SchedulerId = "Scheduler-Core";
// we take this from appsettings.json, just show it's possible
// q.SchedulerName = "Quartz ASP.NET Core Sample Scheduler";
// as of 3.3.2 this also injects scoped services (like EF DbContext) without problems
q.UseMicrosoftDependencyInjectionJobFactory();
// or for scoped service support like EF Core DbContext
// q.UseMicrosoftDependencyInjectionScopedJobFactory();
// these are the defaults
q.UseSimpleTypeLoader();
q.UseInMemoryStore();
......@@ -136,7 +130,7 @@ public void ConfigureServices(IServiceCollection services)
);
q.AddTrigger(t => t
.WithIdentity("Simple Trigger")
.WithIdentity("Simple Trigger")
.ForJob(jobKey)
.StartNow()
.WithSimpleSchedule(x => x.WithInterval(TimeSpan.FromSeconds(10)).RepeatForever())
......@@ -144,7 +138,7 @@ public void ConfigureServices(IServiceCollection services)
);
q.AddTrigger(t => t
.WithIdentity("Cron Trigger")
.WithIdentity("Cron Trigger")
.ForJob(jobKey)
.StartAt(DateBuilder.EvenSecondDate(DateTimeOffset.UtcNow.AddSeconds(3)))
.WithCronSchedule("0/3 * * * * ?")
......@@ -168,7 +162,7 @@ public void ConfigureServices(IServiceCollection services)
.WithDescription("my awesome daily time interval trigger")
.ModifiedByCalendar(calendarName)
);
// also add XML configuration and poll it for changes
q.UseXmlSchedulingConfiguration(x =>
{
......@@ -180,7 +174,7 @@ public void ConfigureServices(IServiceCollection services)
// convert time zones using converter that can handle Windows/Linux differences
q.UseTimeZoneConverter();
// auto-interrupt long-running job
q.UseJobAutoInterrupt(options =>
{
......@@ -225,12 +219,12 @@ public void ConfigureServices(IServiceCollection services)
});
*/
});
// we can use options pattern to support hooking your own configuration
// because we don't use service registration api,
// because we don't use service registration api,
// we need to manually ensure the job is present in DI
services.AddTransient<ExampleJob>();
services.Configure<SampleOptions>(Configuration.GetSection("Sample"));
services.AddOptions<QuartzOptions>()
.Configure<IOptions<SampleOptions>>((options, dep) =>
......@@ -244,8 +238,8 @@ public void ConfigureServices(IServiceCollection services)
.ForJob(jobKey)
.WithCronSchedule(dep.Value.CronSchedule));
}
});
});
// Quartz.Extensions.Hosting allows you to fire background service that handles scheduler lifecycle
services.AddQuartzHostedService(options =>
{
......
......@@ -78,16 +78,10 @@ public void ConfigureServices(IServiceCollection services)
{
// handy when part of cluster or you want to otherwise identify multiple schedulers
q.SchedulerId = "Scheduler-Core";
// we take this from appsettings.json, just show it's possible
// q.SchedulerName = "Quartz ASP.NET Core Sample Scheduler";
// as of 3.3.2 this also injects scoped services (like EF DbContext) without problems
q.UseMicrosoftDependencyInjectionJobFactory();
// or for scoped service support like EF Core DbContext
// q.UseMicrosoftDependencyInjectionScopedJobFactory();
// these are the defaults
q.UseSimpleTypeLoader();
q.UseInMemoryStore();
......@@ -120,7 +114,7 @@ public void ConfigureServices(IServiceCollection services)
);
q.AddTrigger(t => t
.WithIdentity("Simple Trigger")
.WithIdentity("Simple Trigger")
.ForJob(jobKey)
.StartNow()
.WithSimpleSchedule(x => x.WithInterval(TimeSpan.FromSeconds(10)).RepeatForever())
......@@ -128,7 +122,7 @@ public void ConfigureServices(IServiceCollection services)
);
q.AddTrigger(t => t
.WithIdentity("Cron Trigger")
.WithIdentity("Cron Trigger")
.ForJob(jobKey)
.StartAt(DateBuilder.EvenSecondDate(DateTimeOffset.UtcNow.AddSeconds(3)))
.WithCronSchedule("0/3 * * * * ?")
......@@ -152,7 +146,7 @@ public void ConfigureServices(IServiceCollection services)
.WithDescription("my awesome daily time interval trigger")
.ModifiedByCalendar(calendarName)
);
// also add XML configuration and poll it for changes
q.UseXmlSchedulingConfiguration(x =>
{
......@@ -164,7 +158,7 @@ public void ConfigureServices(IServiceCollection services)
// convert time zones using converter that can handle Windows/Linux differences
q.UseTimeZoneConverter();
// auto-interrupt long-running job
q.UseJobAutoInterrupt(options =>
{
......@@ -209,12 +203,12 @@ public void ConfigureServices(IServiceCollection services)
});
*/
});
// we can use options pattern to support hooking your own configuration
// because we don't use service registration api,
// because we don't use service registration api,
// we need to manually ensure the job is present in DI
services.AddTransient<ExampleJob>();
services.Configure<SampleOptions>(Configuration.GetSection("Sample"));
services.AddOptions<QuartzOptions>()
.Configure<IOptions<SampleOptions>>((options, dep) =>
......@@ -228,8 +222,8 @@ public void ConfigureServices(IServiceCollection services)
.ForJob(jobKey)
.WithCronSchedule(dep.Value.CronSchedule));
}
});
});
// Quartz.Extensions.Hosting allows you to fire background service that handles scheduler lifecycle
services.AddQuartzHostedService(options =>
{
......
using System.Runtime.CompilerServices;
[assembly: InternalsVisibleTo("Quartz.Tests.Unit, PublicKey=00240000048000009400000006020000002400005253413100040000010001004b50e2d982a20034afa89fe27c0e690110ca65b8f758bb1b7c8ddac1b5a23426ee206ec904e60679567b8faf329df6671793c8178daca1d2db7e71ee1695b7eeb570c030de77392a86ccc533ce38e892ee97b826ed5bb5d789216d900fc941975688a7709fc967d1cafd39a6952c666ea706e68f7db3f2e43c4991fc148b54b7")]
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Description>Quartz.NET Generic Host integration; $(Description)</Description>
<TargetFrameworks>net6.0;netstandard2.0</TargetFrameworks>
<RootNamespace>Quartz</RootNamespace>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<Authors>Andrew Lock, Marko Lahma, Quartz.NET</Authors>
</PropertyGroup>
<ItemGroup>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Quartz\Quartz.csproj" />
</ItemGroup>
</Project>
......@@ -26,6 +26,7 @@
using Quartz.Impl.Calendar;
using Quartz.Impl.Triggers;
using Quartz.Simpl;
using Quartz.Spi;
using Quartz.Util;
namespace Quartz.Tests.Unit.Impl.Calendar;
......@@ -93,6 +94,43 @@ public void TestTimeZone()
Assert.IsTrue(dailyCalendar.IsTimeIncluded(timeToCheck));
}
[Test]
public void TestTimeZone2()
{
DailyCalendar dailyCalendar = new DailyCalendar("00:00:00", "04:00:00");
dailyCalendar.TimeZone = TimeZoneInfo.Utc;
var trigger = (IOperableTrigger)TriggerBuilder
.Create()
.WithIdentity("TestTimeZone2Trigger")
.StartAt(DateBuilder.EvenMinuteDateAfterNow())
.WithSimpleSchedule(s => s
.WithIntervalInMinutes(1)
.RepeatForever())
.Build();
var fireTimes = TriggerUtils.ComputeFireTimes(trigger, dailyCalendar, (int)TimeSpan.FromDays(1).TotalMinutes);
var timeZoneOffset = TimeZoneInfo.Local.BaseUtcOffset;
// Trigger need to fire during the period when the local timezone and utc timezone are on different day
if (timeZoneOffset > TimeSpan.Zero)
{
// Trigger must fire between midnight and utc offset if positive offset.
fireTimes.Where(t => t.Hour >= 0 && t.Hour <= timeZoneOffset.Hours).Should().NotBeEmpty();
}
else if (timeZoneOffset < TimeSpan.Zero)
{
// Trigger must fire between midnight minus utc offset and midnight if negative offset.
fireTimes.Where(t => t.Hour >= 24 - timeZoneOffset.Hours && t.Hour <= 23).Should().NotBeEmpty();
}
else
{
// Trigger must not fire between midnight and utc offset if offset is UTC (zero)
fireTimes.Where(t => t.Hour >= 0 && t.Hour <= timeZoneOffset.Hours).Should().BeEmpty();
}
}
[Test]
public void ShouldAllowExactMidnight()
{
......
......@@ -804,7 +804,7 @@ public override string ToString()
/// <returns></returns>
private static DateTimeOffset GetStartOfDay(DateTimeOffset time)
{
return time.Date;
return new DateTimeOffset(new DateTime(time.Year, time.Month, time.Day, 0, 0, 0, 0), time.Offset);
}
/// <summary>
......@@ -814,8 +814,7 @@ private static DateTimeOffset GetStartOfDay(DateTimeOffset time)
/// <returns></returns>
private static DateTimeOffset GetEndOfDay(DateTimeOffset time)
{
DateTime endOfDay = new DateTime(time.Year, time.Month, time.Day, 23, 59, 59, 999);
return endOfDay;
return new DateTimeOffset(new DateTime(time.Year, time.Month, time.Day, 23, 59, 59, 999), time.Offset);
}
/// <summary>
......