Is it possible through a package to adjust the way...
# package-development
l
Is it possible through a package to adjust the way Umbraco's cron-type jobs
RecurringHostedServiceBase
methods run? https://github.com/umbraco/Umbraco-CMS/blob/a49a9851dc81677637ec1823963c50d84ef360f3/src/Umbraco.Infrastructure/HostedServices/RecurringHostedServiceBase.cs I'd like to adjust them so that they support running in a time-window, rather than at a specific time. If possible, could anyone point me in the right diretcion for getting started?
j
Is this all scheduled tasks, or just specific ones?
If you only want to do it for your tasks just pop a random delay in the task
Copy code
csharp
await Task.Delay(random.Next(0, 3600) * 1000);
s
Is this to change when the built-in tasks in Umbraco run? If yes, then please don't, we'll never be able to debug your problems. Otherwise, what Jason said! ๐Ÿ‘
Or
if(time <= 01:00:00 && time => 03:00:00) { return; }
(pseudo code)
r
If itโ€™s for you own tasks why not use Hangfire? You could use @Sebastiaanโ€™s integration https://our.umbraco.com/packages/developer-tools/cultivhangfire/
l
It's for the built-in tasks. I'd like to optionally adjust some of them to run in a carbon-aware mode, where the cron job is deferred if the data-center is currently consuming high carbon-intensity energy. I'd be using the Carbon Aware SDK from the green software foundation as the datasource. https://github.com/Green-Software-Foundation/carbon-aware-sdk It's mostly as a proof of concept at the moment, I'd like to measure how much a typical .net/umbraco site can save by introducing something like this
s
Oh that's a very cool idea!
j
OIC - yes that is very cool! As it stands, the RecurringHostedServiceBase won't support that paradigm nicely as Umbraco has no concept of task management. I did suggest this exact use case as a potential benefit of moving to background jobs (and adding some nice abstractions to give us more control over tasks) - there's an open discussion and PR here: https://github.com/umbraco/Umbraco-CMS/discussions/14292 But just because it's not nice doesn't mean it's not possible! You can fetch the hosted services in question directly from the DI container then stop and dispose them. You could then add in your own hosted services that wrap/extend the default ones with different timing logic.
l
thanks for the detail. Much appreciated!