public void ShouldBeAbleToScheduleAndRunJobs()
        {
            var scheduler = LongJobs.CreateScheduler();

            // Scheduling may occur at runtime.

            scheduler.Schedule <CronJob>("* * * * *");
            scheduler.Schedule <CronJob>("* * * * *", DateTimeOffset.UtcNow);

            using (LongJobs.Run(scheduler))
            {
                scheduler.Schedule <FireAndForgetJob>(DateTimeOffset.UtcNow);

                while (CronJob.Invokations == 0 &&
                       FireAndForgetJob.Invokations == 0)
                {
                    Thread.Sleep(100);
                }

                Thread.Sleep(500);

                Assert.AreEqual(1, CronJob.Invokations);
                Assert.AreEqual(1, FireAndForgetJob.Invokations);
            }
        }
        /// <summary>
        /// Adds a LongRunner scheduler to the specified builder and registers it
        /// for startup when the container is built.
        /// </summary>
        /// <param name="builder">The builder to add LongRunner to.</param>
        public static void AddLongRunner(this ContainerBuilder builder)
        {
            builder.Register(c => LongJobs.CreateScheduler(new LongAutofacActivator(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)
        {
            LongJobs.DefaultJobActivator = new DefaultJobActivator();

            var scheduler = LongJobs.CreateScheduler();

            scheduler.Schedule <ConsoleWriteTestJob>("* * * * *");

            var otherScheduler = LongJobs.CreateScheduler(new OtherJobActivator());

            otherScheduler.Schedule <ConsoleWriteTestJob>("*/2 * * * *");

            using (LongJobs.Run(scheduler))
                using (LongJobs.Run(otherScheduler))
                {
                    Console.ReadKey(true);
                }
        }
        public static void Run(string[] args)
        {
            // Every minute.
            var scheduler = LongJobs.CreateScheduler();

            scheduler.Schedule <ConsoleWriteTestJob>("* * * * *");

            // Every five minutes.
            var otherScheduler = LongJobs.CreateScheduler();

            otherScheduler.Schedule <OtherConsoleWriteTestJob>("0 0/5 * 1/1 * ? *");

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