umbraco / Umbraco-CMS

Umbraco is a free and open source .NET content management system helping you deliver delightful digital experiences.
https://umbraco.com
MIT License
4.41k stars 2.66k forks source link

Can't schedule a background task to run with a delay, or period, of 50 days or more. #16936

Open JasonElkin opened 3 weeks ago

JasonElkin commented 3 weeks ago

Which Umbraco version are you using? (Please write the exact version, example: 10.1.0)

13.4.1

Bug summary

IRecurringBackgroundJob doesn't support TimeSpans of 4294967295 milliseconds or greater (about 49.7 days).

Specifics

I understand that this is a limitation of the underlying implementation of System.Threading.Timer, but I don't think that limitation should apply to Umbraco's scheduled tasks.

Steps to reproduce

  1. Create a new IRecurringBackgroundJob as per the docs: https://docs.umbraco.com/umbraco-cms/reference/scheduling#minimal-example
  2. Set the Period as follows:
    public TimeSpan Period { get => TimeSpan.FromDays(50); }

Expected result / actual result

Umbraco Schedules a task for 50 days in the future.

github-actions[bot] commented 3 weeks ago

Hi there @JasonElkin!

Firstly, a big thank you for raising this issue. Every piece of feedback we receive helps us to make Umbraco better.

We really appreciate your patience while we wait for our team to have a look at this but we wanted to let you know that we see this and share with you the plan for what comes next.

We wish we could work with everyone directly and assess your issue immediately but we're in the fortunate position of having lots of contributions to work with and only a few humans who are able to do it. We are making progress though and in the meantime, we will keep you in the loop and let you know when we have any questions.

Thanks, from your friendly Umbraco GitHub bot :robot: :slightly_smiling_face:

JasonElkin commented 3 weeks ago

I think that the Timer API is too low level to properly support the kind of scheduled tasks that a web application might need to handle.

We should really have an extra abstraction layer responsible for scheduling tasks independently of their invocation, rather than doing both with the System.Threading.Timer.

An abstraction for scheduling would also make it possible to support scheduling tasks in "human" time, using DateTime or cron expressions - which currently can't be supported.

enkelmedia commented 2 weeks ago

@JasonElkin feel like the built in stuff is intended for thing that happens with quite a smaller interval?

I tend to use Hangfire for situations like this, and this great dashboard https://marketplace.umbraco.com/package/cultiv.hangfire from @nul800sebastiaan

Is that an option?

JasonElkin commented 2 weeks ago

@enkelmedia yeah, perhaps this is in part a docs/naming issue and Umbraco doesn't actually have task "scheduling" built in.

In fairness, the way things are named in code doesn't really point to "scheduling". My frustration is that the implementation is so close to being able to run tasks on a schedule that it's odd that we don't have that functionality built in.