-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #478 from bcgov/yj
Yj
- Loading branch information
Showing
3 changed files
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
server/StrDss.Service/Hangfire/DisableConcurrentExecutionAttribute.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using Hangfire.Common; | ||
using Hangfire.Server; | ||
using Hangfire; | ||
|
||
namespace StrDss.Service.Hangfire | ||
{ | ||
/// <summary> | ||
/// Usage: | ||
/// | ||
/// [DisableConcurrentExecution(timeoutInSeconds: 10 * 60)] | ||
/// | ||
/// </summary> | ||
|
||
public class DisableConcurrentExecutionAttribute : JobFilterAttribute, IServerFilter | ||
{ | ||
private readonly int _timeoutInSeconds; | ||
|
||
public DisableConcurrentExecutionAttribute(int timeoutInSeconds) | ||
{ | ||
_timeoutInSeconds = timeoutInSeconds; | ||
} | ||
|
||
public void OnPerforming(PerformingContext filterContext) | ||
{ | ||
var jobId = filterContext.BackgroundJob.Id; | ||
var connection = JobStorage.Current.GetConnection(); | ||
var currentJob = connection.GetJobData(jobId); | ||
|
||
if (currentJob != null && currentJob.State == "Processing") | ||
{ | ||
throw new InvalidOperationException("This job is already being processed."); | ||
} | ||
} | ||
|
||
public void OnPerformed(PerformedContext filterContext) | ||
{ | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters