Hangfire: MinuteInterval will be deprecated in version 2.0

Created on 27 Apr 2019  路  10Comments  路  Source: HangfireIO/Hangfire

What's the replacement. Don't see a good option from the suggestions provided. I had this
return Cron.MinuteInterval(int.Parse(jobScheduler.Duration)); and now I am using return Cron.Hourly(int.Parse(jobScheduler.Duration)); but that does not represent what I want which is a job that runs after every 30 minutes and NOT 30 minutes into the hour

Most helpful comment

So there is no helper to create these cryptics error prone strings ? This is not a progress ... one step back...

All 10 comments

Looking into the code, the MinuteInterval just does $"*/{interval} * * * *":
https://github.com/HangfireIO/Hangfire/blob/9cd09f38fa97e4c2dd48f6097985fd2b48b4568e/src/Hangfire.Core/Cron.cs#L231

Therefore
Cron.MinuteInterval(int.Parse(jobScheduler.Duration));
should be equivalent to
$"*/{jobScheduler.Duration} * * * *"

So there is no helper to create these cryptics error prone strings ? This is not a progress ... one step back...

Well, it's just cron expressions. While I agree they are not very readable to anyone who doesn't work with Linux regularly, there are some tools to help with them. E.g. crontab.guru. I haven't looked, but there might be some good nuget packages for creating these as well.

A builder class for cron would be nice. I thought you replaced these methods with a builder class. But no.

You might notice I'm not involved with this repository/library in any capacity. Found this issue a while back, wanted to share a workaround. You will need to wait for the official maintainers to get any APIs changed to your liking.

When I looked into this I ended up using https://github.com/bradymholt/cron-expression-descriptor/issues/123#issuecomment-532056815 (As HF ultimately uses https://github.com/bradymholt/cron-expression-descriptor) and that maintainer also did not want to add a builder ;-)

So there is no helper to create these cryptics error prone strings ? This is not a progress ... one step back...

hey! here's an idea, migrate from hangfire to azure functions..

Tried to use CronEspresso

string cronExpression = CronEspresso.NETCore.CronGenerator.GenerateMinutesCronExpression(5);

Result: System.ArgumentException: 'CRON expression is invalid. Please see the inner exception for details.
Parameter name: cronExpression'
Inner Exception: CronFormatException: Wrong number of parts in the 0 0/5 * 1/1 * ? * cron expression, you can only use 5 or 6 (with seconds) part-based expressions.

Error: Wrong number of parts in the 0 20 1 * cron expression, you can only use 5 or 6 (with seconds) part-based expressions.

Readable code is a huge must have. -> Making something that requires working with Linux a requirement, and ontop -> Having to use 3rd party tools to make / figure out what a cron expression means.

I think this is not a good solution.

The fact that there is even a discussion going on, on this issue about how these cron expressions work, just emphasizes my concern.

Readable Code > Reverting to old standards. -> If we just continued to do "like we've always done", we never move forward.

Was this page helpful?
0 / 5 - 0 ratings