Closed JustinAren closed 4 years ago
I don't know if it's Hangfire or RedistStorage bug, but it seems that recurring jobs marked with DisableConcurrentExecution are still trying to launch every period and they wait for timeout set in the attribute. I suppose that the logic should be not to launch a job if timeout is not expired
I believe that is already solved. I've tried the following code in a linqpad window and it does work as expected.
void Main()
{
var storage = new RedisStorage();
var options = new BackgroundJobServerOptions() { Queues = new[] { "myqueue" }};
var js = new BackgroundJobServer(options, storage);
var client = new BackgroundJobClient(storage);
client.Enqueue<DummyClass>(x=> x.PaymentEngineProcessAsync("", "", null));
client.Enqueue<DummyClass>(x=> x.PaymentEngineProcessAsync("", "", null));
LINQPad.Util.KeepRunning();
}
public class DummyClass
{
// Define other methods, classes and namespaces here
[Hangfire.Queue("myqueue")]
[DisableConcurrentExecution(10)]
public void PaymentEngineProcessAsync(string specificAcquirer = null, string commandlineParameters = null, PerformContext context = null)
{
$"Starting {DateTime.Now}".Dump();
Thread.Sleep(60000);
$"Done {DateTime.Now}".Dump();
}
}
Output is:
Starting 09/01/2020 12:01:03
Done 09/01/2020 12:02:03
Starting 09/01/2020 12:02:03
Done 09/01/2020 12:03:03
Hi,
I want to use the DisableConcurrentExecution attribute to prevent that some jobs are running multiple times at the same time, but it does not seems to work.
As you can see in the following screendumps, both jobs started at the same time, and bot jobs ended at almost the same time. Also, in Redis I don't see any evidence of a lock object being created
First execution:![disableconcurrentexecution job 1](https://user-images.githubusercontent.com/9365859/30059114-0dea0a1c-923e-11e7-91a3-d8920e7be26f.png)
Second execution:![disableconcurrentexecution job 2](https://user-images.githubusercontent.com/9365859/30059116-0e11c552-923e-11e7-9e5c-3aec67da189a.png)
I am using the following code:
And I am using the following packages and versions:
Am I doing something wrong?
Many thanks in advance.
Justin