There are two settings that you pass into the base recurring task, one called
DelayBeforeWeStart
And another called
HowOftenWeRepeat
So the DelayBeforeWeStart is a time span from when the task is registered when it first runs..
And HowOftenWeRepeat more obviously the time span in between each running of the task..
... So since these two values are set in code, if you wanted the task to run everyday at the same time.... You'd set the DelayBeforeWeStart value to be the time span between 'Now' and the time you want it to run...
Which will be different depending on whenever the site restarts...
How do I calculate and then pass the value for DelayBeforeWeStart? Not so much calculate it, but pass it to "base" in the constructor? The run at time is defined in appSettings.
Use RecurringHostedServiceBase to run at a specific time
Looking to use RecurringHostedServiceBase to run a task at a specific time each day, but that doesn't appear to be an option?
https://docs.umbraco.com/v/10.x-lts/umbraco-cms/reference/scheduling
Is it simply a case of running it frequently (?) and checking to see if it's the right time before continuing?
Hi Gordon
There are two settings that you pass into the base recurring task, one called
DelayBeforeWeStart
And another called
HowOftenWeRepeat
So the DelayBeforeWeStart is a time span from when the task is registered when it first runs..
And HowOftenWeRepeat more obviously the time span in between each running of the task..
... So since these two values are set in code, if you wanted the task to run everyday at the same time.... You'd set the DelayBeforeWeStart value to be the time span between 'Now' and the time you want it to run...
Which will be different depending on whenever the site restarts...
... If that makes sense.?
Regards
Marc
Ah, OK.
So, HowOftenWeRepeat would be
How do I calculate and then pass the value for DelayBeforeWeStart? Not so much calculate it, but pass it to "base" in the constructor? The run at time is defined in appSettings.
Hi Gordon
So would you be able to set
DelayBeforeWeStart => GetDelayBeforeWeStart();
and have that function return the number of seconds?
and that function would have something like this in?
eg to run at eleven thirty in the evening:
sorry I am guessing a bit!
regards
Marc
The solution was to use the IOptions pattern to allow for getting the settings from appSettings.
So, I now have this:
With this for the Settings:
And this in an IComposer
So, it defaults to run at 6am each day, but that can be (is) overriden by a value in appSettings
Hi
Where did you define GetNotificationDelay? :)
How is your RunAtTime expression being used?
Hi
Can you explain more on this line:
I'm not sure where this is coming from
trying to have a task running from a cron value set ind the appsettings :)
Thank! :)
I have tried to make a function that returns the TimeSpan
And then used it in the base:
But it's never triggert.
is working on a reply...