Browse Source

Attach a TriggerKey to the Quartz.NET trigger registered by OpenIddict

Co-Authored-By: Robin Sue <7110884+Suchiman@users.noreply.github.com>
pull/1576/head
Kévin Chalet 3 years ago
parent
commit
e957e8e3af
  1. 9
      src/OpenIddict.Abstractions/OpenIddictResources.resx
  2. 1
      src/OpenIddict.Quartz/OpenIddictQuartzConfiguration.cs
  3. 4
      src/OpenIddict.Quartz/OpenIddictQuartzJob.cs
  4. 12
      test/OpenIddict.Quartz.Tests/OpenIddictQuartzConfigurationTests.cs

9
src/OpenIddict.Abstractions/OpenIddictResources.resx

@ -2506,4 +2506,13 @@ This may indicate that the hashed entry is corrupted or malformed.</value>
<data name="ID8002" xml:space="preserve">
<value>Starts the scheduled task at regular intervals.</value>
</data>
<data name="ID8003" xml:space="preserve">
<value>OpenIddict job</value>
</data>
<data name="ID8004" xml:space="preserve">
<value>Built-in automatic trigger</value>
</data>
<data name="ID8005" xml:space="preserve">
<value>OpenIddict/Quartz.NET integration</value>
</data>
</root>

1
src/OpenIddict.Quartz/OpenIddictQuartzConfiguration.cs

@ -34,6 +34,7 @@ public sealed class OpenIddictQuartzConfiguration : IConfigureOptions<QuartzOpti
// reached if the application is shut down or recycled. As such, this trigger is set up to fire
// between 1 and 10 minutes after the application starts to ensure the job is executed at least once.
builder.ForJob(OpenIddictQuartzJob.Identity)
.WithIdentity(SR.GetResourceString(SR.ID8004), SR.GetResourceString(SR.ID8005))
.WithSimpleSchedule(options => options.WithIntervalInHours(1).RepeatForever())
.WithDescription(SR.GetResourceString(SR.ID8002))
.StartAt(DateBuilder.FutureDate(new Random().Next(1, 10), IntervalUnit.Minute));

4
src/OpenIddict.Quartz/OpenIddictQuartzJob.cs

@ -38,8 +38,8 @@ public sealed class OpenIddictQuartzJob : IJob
/// Gets the default identity assigned to this job.
/// </summary>
public static JobKey Identity { get; } = new JobKey(
name: typeof(OpenIddictQuartzJob).Name,
group: typeof(OpenIddictQuartzJob).Assembly.GetName().Name!);
name: SR.GetResourceString(SR.ID8003),
group: SR.GetResourceString(SR.ID8005));
/// <inheritdoc/>
public async Task Execute(IJobExecutionContext context)

12
test/OpenIddict.Quartz.Tests/OpenIddictQuartzConfigurationTests.cs

@ -16,7 +16,11 @@ public class OpenIddictQuartzConfigurationTests
configuration.Configure(options);
// Assert
Assert.Contains(options.JobDetails, job => job.Key.Equals(OpenIddictQuartzJob.Identity));
Assert.Equal(1, options.JobDetails.Count);
Assert.Equal(OpenIddictQuartzJob.Identity, options.JobDetails[0].Key);
Assert.Equal(SR.GetResourceString(SR.ID8003), options.JobDetails[0].Key.Name);
Assert.Equal(SR.GetResourceString(SR.ID8005), options.JobDetails[0].Key.Group);
Assert.Equal(SR.GetResourceString(SR.ID8001), options.JobDetails[0].Description);
}
[Fact]
@ -30,6 +34,10 @@ public class OpenIddictQuartzConfigurationTests
configuration.Configure(options);
// Assert
Assert.Contains(options.Triggers, trigger => trigger.JobKey.Equals(OpenIddictQuartzJob.Identity));
Assert.Equal(1, options.Triggers.Count);
Assert.Equal(OpenIddictQuartzJob.Identity, options.Triggers[0].JobKey);
Assert.Equal(SR.GetResourceString(SR.ID8004), options.Triggers[0].Key.Name);
Assert.Equal(SR.GetResourceString(SR.ID8005), options.Triggers[0].Key.Group);
Assert.Equal(SR.GetResourceString(SR.ID8002), options.Triggers[0].Description);
}
}

Loading…
Cancel
Save