예제 #1
0
        public void ShouldBeAbleToScheduleAndRunJobs()
        {
            var scheduler = FastJobs.CreateScheduler();

            scheduler.Schedule <TestJob>(TimeSpan.FromSeconds(5));

            using (FastJobs.Run(scheduler))
            {
                Thread.Sleep(1000);
            }

            Assert.AreEqual(1, TestJob.Invokations);
        }
예제 #2
0
        /// <summary>
        /// Adds a FastRunner scheduler to the specified builder and registers it
        /// for startup when the container is built.
        /// </summary>
        /// <param name="builder">The builder to add FastRunner to.</param>
        public static void AddFastRunner(this ContainerBuilder builder)
        {
            builder.Register(c => FastJobs.CreateScheduler(new FastAutofacActivator(c.Resolve <ILifetimeScope>())))
            .AsSelf()
            .SingleInstance();

            builder.RegisterType <JobStartup>()
            .AsSelf()
            .SingleInstance();

            // Resolve JobStartup so that it lives along with the container.
            builder.RegisterBuildCallback(c => c.Resolve <JobStartup>());
        }
        public static void Run(string[] args)
        {
            var scheduler = FastJobs.CreateScheduler();

            scheduler.Schedule <ConsoleWriteTestJob>(TimeSpan.FromSeconds(5));

            var otherScheduler = FastJobs.CreateScheduler();

            otherScheduler.Schedule <OtherConsoleWriteTestJob>(TimeSpan.FromSeconds(1));

            using (FastJobs.Run(scheduler))
                using (FastJobs.Run(otherScheduler))
                {
                    Console.ReadKey(true);
                }
        }