Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issues recurring job #1832

Open
TranHDung opened this issue Mar 22, 2021 · 11 comments
Open

Issues recurring job #1832

TranHDung opened this issue Mar 22, 2021 · 11 comments

Comments

@TranHDung
Copy link

TranHDung commented Mar 22, 2021

Hi every one,

I am having an issue with my cron job for automatically sending email.

Firstly, As a user I set the time for the job to send an email every 50 minutes, starting 9.00am.

The job is working fine at 9.50am and I can receive an email.

The Next email is expected to be sent in the next 50 minutes. But the problem is:

At 10.00am, an email is sent. After that, 10.50am, an email is sent.

At 11.00am, an email is sent. After that, 11.50am, an email is sent.

if (entity.Minute <= 59) { RecurringJob.AddOrUpdate($"RecurringNotAppear-{entity.Id}", () => SendMail(entity), $"*/{entity.Minute} * * * *"); return; }

@TranHDung TranHDung changed the title Issues recurring jon Issues recurring job Mar 22, 2021
@cah-sachin
Copy link

Hangfire Team,

we are observing the same issue. Our Hangfire job is set for running every hour, though we see that job run at multiple time within that one hour, maximum 20 times. Is this an existing issue, please acknowledge it, our production is getting impacted.

@cah-sachin
Copy link

Hangfire Team,

Let me know if other details are required.

sachin

@cah-sachin
Copy link

Anything Hangfire team.

@odinserj
Copy link
Member

odinserj commented Apr 5, 2021

Please see https://en.wikipedia.org/wiki/Cron

Note that frequencies in general cannot be expressed; only step values which evenly divide their range express accurate frequencies (for minutes and seconds, that's /2, /3, /4, /5, /6, /10, /12, /15, /20 and /30 because 60 is evenly divisible by those numbers; for hours, that's /2, /3, /4, /6, /8 and /12); all other possible "steps" and all other fields yield inconsistent "short" periods at the end of the time-unit before it "resets" to the next minute, second, or day; for example, entering */5 for the day field sometimes executes after 1, 2, or 3 days, depending on the month and leap year; this is because cron is stateless (it does not remember the time of the last execution nor count the difference between it and now, required for accurate frequency counting—instead, cron is a mere pattern-matcher).

@cah-sachin
Copy link

@odinserj
we started memory based hangfire job. What we are observing is mentioned here also
#1197

We are seeing hangfire starting another thread while the main is in progress. Maximum count reaches to 20. This has nothing to do with cron job expression. Do you need any more details then explanation in 1197 ?

@odinserj
Copy link
Member

odinserj commented Apr 5, 2021

Try to use attribute from this gist – https://gist.github.com/odinserj/a6ad7ba6686076c9b9b2e03fcf6bf74e

[SkipWhenPreviousJobIsRunning]
public void YourBackgroundJobMethod()
{
     // ...
}

In this case new background job will not be created if recurring job is still running.

@cah-sachin
Copy link

We will try this and let you know our outcome @odinserj

@cah-sachin
Copy link

@odinserj Which nuget package/version have SkipWhenPreviousJobIsRunning option so we can try ?

@Nikhil-T1
Copy link

@odinserj We tried SkipWhenPreviousJobIsRunning but it did not work. Can this be used with in memory Hangfire job setup or it needs only Redis or some sql storage?
Can you add this in the Hangfire nuget package so that we can just use the attribute instead of copying the snippet of code you provided?

@odinserj
Copy link
Member

odinserj commented Apr 6, 2021

Please post here all the configuration logic related to Hangfire. All NuGet packages related to Hangfire and their versions. Please include screenshots of Dashboard UI for affected jobs.

The problem is I still don't understand what's happened – two issues totally unrelated to each other were referenced without much details. And my assumption was based only on a regular issue when recurring job is based on a long running method that takes more time to be processed than its recurring interval.

Please try to describe the problem. The more words the better, because I will be able to catch more facts. Describe both actual and expected behaviors.

And last – if you are using Hangfire.MemoryStorage for your in-memory setup, try to use Hangfire.InMemory instead – https://github.com/HangfireIO/Hangfire.InMemory

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

5 participants