Skip to content

Commit 739f292

Browse files
committed
Add DisallowConcurrentExecution to JobTriggerAttribute
Allow configuration of job concurrency via JobTriggerAttribute. Constructor now accepts disallowConcurrentExecution parameter. Job registration uses this setting to control concurrent execution.
1 parent db3bb60 commit 739f292

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

Sources/EasyExtensions.Quartz/Attributes/JobTriggerAttribute.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@ public class JobTriggerAttribute : Attribute
2929
/// </summary>
3030
public string? CronSchedule { get; }
3131

32+
/// <summary>
33+
/// Gets or sets a value indicating whether concurrent execution of this operation is disallowed.
34+
/// </summary>
35+
/// <remarks>When set to <see langword="true"/>, attempts to execute the operation concurrently
36+
/// may be prevented, depending on the implementation. This can be used to ensure that only one instance of the
37+
/// operation runs at a time.</remarks>
38+
public bool DisallowConcurrentExecution { get; set; } = true;
39+
3240
/// <summary>
3341
/// Create a new instance of <see cref="JobTriggerAttribute"/>.
3442
/// </summary>
@@ -38,10 +46,11 @@ public class JobTriggerAttribute : Attribute
3846
/// <param name="seconds"> Interval: Seconds. </param>
3947
/// <param name="startNow"> Start now. </param>
4048
/// <param name="repeatForever"> Interval: Repeat forever. </param>
49+
/// <param name="disallowConcurrentExecution"> Indicates whether concurrent execution of this operation is disallowed. </param>
4150
/// <param name="cronSchedule"> Cron schedule, if specified, it will override the interval. <br/>
4251
/// See <see href="https://www.quartz-scheduler.org/documentation/quartz-2.3.0/tutorials/crontrigger.html">Quartz CronTrigger Documentation</see> for more information. </param>
4352
public JobTriggerAttribute(int days = 0, int hours = 0, int minutes = 0, int seconds = 0,
44-
bool startNow = true, bool repeatForever = true, string? cronSchedule = "")
53+
bool startNow = true, bool repeatForever = true, string? cronSchedule = "", bool disallowConcurrentExecution = true)
4554
{
4655
TimeSpan interval = new TimeSpan(days, hours, minutes, seconds);
4756
if (interval <= TimeSpan.Zero && string.IsNullOrWhiteSpace(cronSchedule))
@@ -52,6 +61,7 @@ public JobTriggerAttribute(int days = 0, int hours = 0, int minutes = 0, int sec
5261
CronSchedule = cronSchedule;
5362
RepeatForever = repeatForever;
5463
Interval = new TimeSpan(days, hours, minutes, seconds);
64+
DisallowConcurrentExecution = disallowConcurrentExecution;
5565
}
5666
}
5767
}

Sources/EasyExtensions.Quartz/Extensions/ServiceCollectionExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ private static void SetupQuartz(IServiceCollectionQuartzConfigurator configurato
6767
var jobKey = new JobKey(job.Name);
6868
configurator.AddJob(job, jobKey, x => x
6969
.WithIdentity(jobKey)
70-
.DisallowConcurrentExecution());
70+
.DisallowConcurrentExecution(concurrentExecutionDisallowed: jobTriggerAttribute.DisallowConcurrentExecution));
7171
configurator.AddTrigger(opts =>
7272
{
7373
opts.ForJob(jobKey)

0 commit comments

Comments
 (0)