public void Should_run_every_scheduled_second_with_providing_instance() { var testJob = new TestJob2(); var scheduler = new DefaultSchedulerFactory().Create(); scheduler.Setup( Job.Run(testJob.RunJob).Every(1.Second()) ).Start(); Thread.Sleep(TimeSpan.FromSeconds(5)); scheduler.Stop(); Assert.That(testJob.TimesCalled, Is.EqualTo(5)); }
public void Should_run_multiple_jobs_at_scheduled_interval() { var container = new WindsorContainer(); var testJob = new TestJob(); var testJob2 = new TestJob2(); container.Register( Component.For<TestJob>().Instance(testJob), Component.For<TestJob2>().Instance(testJob2)); var scheduler = new DefaultSchedulerFactory().UseContainer(() => new WindsorServiceLocator(container)).Create(); scheduler.Setup( Job.Run<TestJob>(x => x.RunJob()).Every(1.Second()), Job.Run<TestJob2>(x => x.RunJob()).Every(2.Seconds()) ).Start(); Thread.Sleep(TimeSpan.FromSeconds(6)); scheduler.Stop(); Assert.That(testJob.TimesCalled, Is.EqualTo(6)); Assert.That(testJob2.TimesCalled, Is.EqualTo(3)); container.Dispose(); }
public virtual Task HandleAsync(TestJob2 job, CancellationToken cancellationToken) { return(Task.CompletedTask); }