Repository navigation
SchedulerTimeSettings
blehnen edited this page Nov 10, 2026
·
4 revisions
You can inject time providers from any transport into a scheduler or into a transport of another type.
[Scheduler]
private static List<IDisposable> _extraQueueContainers = new List<IDisposable>();
//all schedulers created from this container will get the indicated time provider
using (var jobContainer = new JobSchedulerContainer(QueueCreation))
{
//scheduler creation, add jobs, etc...
}
//once processing is complete
foreach (var dis in _extraQueueContainers)
{
dis.Dispose();
}
_extraQueueContainers.Clear();
private static void QueueCreation(IContainer container)
{
container.Register<IGetTimeFactory>(CreateTimeClass, LifeStyles.Singleton);
}
private static IGetTimeFactory CreateTimeClass()
{
var queueContainer = new QueueContainer<RedisQueueInit>(x => { }, SetOptions);
_extraQueueContainers.Add(queueContainer);
return queueContainer.CreateTimeSync("192.168.0.212");
}
private static void SetRedisOption(IContainer container)
{
var options = container.GetInstance<RedisQueueTransportOptions>();
options.TimeServer = TimeLocations.SntpServer;
}[Consumers]
If you inject a time provider into a scheduler, you might want to add the same time provider to the consumers. Do this the same way, but on a QueueContainer instead of a JobSchedulerContainer.
You can inject a time provider from one transport into another. For instance, you could make a redis queue get its time from a SQL server instance.
The only thing to keep in mind is that the container that created the time provider must stay alive and in scope. If it is disposed or goes out of scope before the consumer finishes running, errors are thrown when the time factory is accessed.
For any issues please use the GitHub issues