codeyu / Hangfire.LiteDB

LiteDB storage for Hangfire.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Hangfire Job starts multiple times

cemmons opened this issue · comments

Hi, I'm having problems with my LiteDB storage.

I queued a job and i have 10 Workers on my Server. several times I see that the same job is running under several workers:

image

I have tried using a lock object but it's not working.

Firstly, thank you for providing the litedb implementation for hangfire. One of the project i am working on is using LiteDB heavily and i was looking to use Hangfire within the project and to find an implementation for LiteDB was absolutely thrilling.

After implementing i notice my one time jobs are being run multiple times just like @cemmons posted in his issue. I download the sample and ran the console sample to see if this issue is specific to me but looks like there is something incorrect in the core implementation as the samples are not working as expected ..

image

The background Job "Hello World" is a one time job but fires like 11 times. I would love to see this issue fixed so i could continue with my project.
Thanks again for your contribution to the community!

Having the same problem here unfortunately! macOS with dotnet core 3.0 preview. My deps are :

  • Hangfire.Core 1.7.0
  • hangfire.litedb 0.1.1

Theres a lot of discussion going on over here at hangfire:
HangfireIO/Hangfire#1025
HangfireIO/Hangfire#1197

And the consensus seems to be that it's a storage provider problem and not a Hangfire problem.

I ended using a lock statement inside my process. and an internal boolean in each job to know if it was taken. Even if N workers grab the job, only one would be able to update the boolean and the others workers would just past by without doing anything.

This is my workaround until a proper fix could by developed.

Same here.
I'm on .Net Core 2.2. My cron jobs triggers twice.

Looks like the problem was fixed by updating the Hangfire to v1.7.0

Looks like the problem was fixed by updating the Hangfire to v1.7.0

I will try to upgrade my project in a branch

Well, it's not fixed. Got 4 calls today.

@igromanru @cemmons It's definitely not fixed in Hangfire 1.7 - as you can see in my post above that's the exact version I'm using - and having the problem :)

I have the same problem in Hangfire 1.6.21 with MySqlStorage

Thanks to @DotNetConcept ’s PR, can anyone test it?

I'm going to run the test on your Unit Test Project and then implement the change on my project to see if it runs ok. I need some time to work with it.

Ok, I ran this test:

image

I did it several number of times and with many number of iterations and it never fired the same job twice..

Thank you, @cemmons . It's looks not bad. I merge PR first. I will release a new version to nuget on this weekend.

I ended using a lock statement inside my process. and an internal boolean in each job to know if it was taken. Even if N workers grab the job, only one would be able to update the boolean and the others workers would just past by without doing anything.

This is my workaround until a proper fix could by developed.

hello, could you provide move detail about your solution?

Ok, I ran this test:

image

I did it several number of times and with many number of iterations and it never fired the same job twice..
for me it doen't work could you show me how you declare storege