HangfireIO / HangfireIO/Hangfire

How to skip concurrent executions without failing the job

Open
#935 4 comments 0 reactions 0 assignees View on GitHub
t: question
Dominant language
C#
Stars
10.1k
Forks
1.8k
Avg merge
1h 19m
Merged PRs (30d)
1

Description

I've got a minutely recurring job that uses `DisableConcurrentExecution(timeout:0)` (0 retries), as only one worker should be processing it at a given time, specially if the job takes more than a minute to complete (it varies).

I don't want the "skipped" jobs to be flagged as `failed` on the dashboard, so I wanted to add a `SkipConcurrentExecutionAttribute` that would be almost identical to `DisableConcurrentExecutionAttribute`, except that it would try/catch around the lock acquisition, and swallow `DistributedLockTimeoutException` and set the job to `DeletedState` with the reason why.

But I can't do this properly, because [GetResource()](https://github.com/HangfireIO/Hangfire/blob/master/src/Hangfire.Core/DisableConcurrentExecutionAttribute.cs#L55) is private, and its implementation refers to other methods that are internal to the library.
`$"{job.Type.ToGenericTypeString()}.{job.Method.Name}"` seems to be the safe way of producing non-conflicting distributed lock names, but I can't refer to it.
Can we have in the lib a public method that generates the job's distributed lock name?

cf., https://discuss.hangfire.io/t/disableconcurentexecution-for-job-groups/1389/4

Contributor guide

Open the contributing guide

Research direction

Start by reading src/Hangfire.Core/DisableConcurrentExecutionAttribute.cs, especially GetResource() and the internal methods it uses to form the distributed lock name. Check how the public API could expose that naming logic for a custom SkipConcurrentExecutionAttribute without relying on private or internal members. Done means the lock name can be generated without conflicting with existing DisableConcurrentExecution behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
backend, distributed-systems
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.