Craig100
02/07/2025, 6:02 PMPeriod = TimeSpan.FromMinutes(GetTime());
just before the return, outside the scope, but although I can see it picks up the new time there, the schedule is still running on the old time.
Is there some tweak that's not in the docs or have I simply misunderstood how the PeriodChanged thing works? I note there is this section:-
private event EventHandler? _periodChanged;
public event EventHandler PeriodChanged
{
add { _periodChanged += value; }
remove { _periodChanged -= value; }
}
Not sure what populates the value
. Should that be my GetTime() function?
Any advice appreciated.
Thanks.Ambert
02/08/2025, 2:00 PMhealthChecksSettings.OnChange(x =>
{
Period = x.Notification.Period;
_periodChanged?.Invoke(this, EventArgs.Empty);
});
Craig100
02/08/2025, 4:24 PMAmbert
02/09/2025, 3:50 PMAmbert
02/09/2025, 3:50 PMCraig100
02/10/2025, 9:31 AMCraig100
02/10/2025, 1:40 PMprivate int GetTime() {
using var context = _contextFactory.EnsureUmbracoContext();
if (context.UmbracoContext.Content == null) {
throw new InvalidOperationException("Application can't access nucache...");
}
var siteSettings = context.UmbracoContext.Content.GetAtRoot().First().FirstChild<SiteSettings>();
int scheduledTimePeriod = siteSettings?.PDfclearanceSchedule ?? 3;
return scheduledTimePeriod;
}
Kevin Jump
02/10/2025, 2:37 PMRecurringHostedBase
. and with that you can call the ChangePeriod
method, and it sets it (and i can confim it works)
so my class
cs
internal class ProcessingQueueBackgroundHostedService
: RecurringHostedServiceBase
{
....
has this method. (you can ignore the buffer stuff, just for me that).
cs
private void SetPeriod(TimeSpan period, bool addBuffer)
{
_currentPeriod = period + (addBuffer ? TimeSpan.FromSeconds(1) : TimeSpan.Zero);
_logger.LogDebug("Setting period to {time} seconds", _currentPeriod.TotalSeconds);
ChangePeriod(_currentPeriod);
}
Kevin Jump
02/10/2025, 2:41 PMKevin Jump
02/10/2025, 2:43 PMcs
_backgroundTaskQueue.QueueBackgroundWorkItem(
cancellationToken => Task.Run(() =>
{ _backgroundService.ProcessQueueItem(notification.QueuedItem.Key);
}, cancellationToken));
Kevin Jump
02/10/2025, 2:44 PMcs
if (await _processingSemaphore.WaitAsync(TimeSpan.FromMinutes(_waitTime)))
{
try
{
// do the things you need here.
}
catch (Exception ex)
{
_logger.LogError(ex, "Error")
}
finally
{
_processingSemaphore.Release();
}
}
Kevin Jump
02/10/2025, 2:46 PMbackgroundHostedService
and a backgroundService
all the work goes on in the backgroundService
the backgroundHostedService is calling it from it's own PerformExecuteAsync method, but also because all the work and guards are in the backgroundservice i can put it on a background thread, and be OK that they won't clash.Craig100
02/10/2025, 4:23 PMinternal class ProcessingQueueBackgroundHostedService
: RecurringHostedServiceBase
I just get an error saying "Base class 'Umbraco.Cms.Infrastructure.HostedServices.RecurringHostedServiceBase' does not contain parameterless constructor" and I can't find any info on it's proper use. Looks like if I could get that bit in and pick up the new period from the backoffice via my GetTime() function then I might be there.Kevin Jump
02/10/2025, 4:44 PM