Skip to content

SchedulerTimeSettings

Brian Lehnen edited this page Aug 3, 2016 · 2 revisions

Job Scheduler Time settings

You may inject time providers from any transport into a scheduler or into a transport of another type.

[Scheduler]

private static List<IDisposable> _extraQueueContainers;

//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 injecting a time provider into a scheduler, you might want the same time provider added to the consumers. This can be done the exact same way, except on a QueueContainer instead of a JobSchedulerContainer.

Note that you can inject a time provider from one transport into another. For instance, you could make a redis queue obtain it's 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 / in scope. If it's disposed or goes out of scope before the consumer has finished running, errors will be thrown when the time factory is accssed.

Clone this wiki locally