コード例 #1
0
        public void TestStoreAndRetrieveTriggers()
        {
            RAMJobStore store = new RAMJobStore();

            // Store jobs and triggers.
            for (int i = 0; i < 10; i++)
            {
                IJobDetail job = JobBuilder.Create <NoOpJob>().WithIdentity("job" + i).Build();
                store.StoreJob(job, true);
                SimpleScheduleBuilder schedule = SimpleScheduleBuilder.Create();
                ITrigger trigger = TriggerBuilder.Create().WithIdentity("job" + i).WithSchedule(schedule).ForJob(job).Build();
                store.StoreTrigger((IOperableTrigger)trigger, true);
            }
            // Retrieve job and trigger.
            for (int i = 0; i < 10; i++)
            {
                JobKey     jobKey    = JobKey.Create("job" + i);
                IJobDetail storedJob = store.RetrieveJob(jobKey);
                Assert.AreEqual(jobKey, storedJob.Key);

                TriggerKey triggerKey    = new TriggerKey("job" + i);
                ITrigger   storedTrigger = store.RetrieveTrigger(triggerKey);
                Assert.AreEqual(triggerKey, storedTrigger.Key);
            }
        }
コード例 #2
0
        public void TestRetrieveTrigger_NoTriggerFound()
        {
            RAMJobStore      store   = new RAMJobStore();
            IOperableTrigger trigger = store.RetrieveTrigger(new TriggerKey("not", "existing"));

            Assert.IsNull(trigger);
        }
コード例 #3
0
        public void TestRetrieveJob_NoJobFound()
        {
            RAMJobStore store = new RAMJobStore();
            IJobDetail  job   = store.RetrieveJob(new JobKey("not", "existing"));

            Assert.IsNull(job);
        }
コード例 #4
0
        /// <summary>
        /// Creates an in memory job store (<see cref="RAMJobStore" />)
        /// The thread priority is set to Thread.NORM_PRIORITY
        /// </summary>
        /// <param name="maxThreads">The number of threads in the thread pool</param>
        public virtual void CreateVolatileScheduler(int maxThreads)
        {
            SimpleThreadPool threadPool = new SimpleThreadPool(maxThreads, ThreadPriority.Normal);

            threadPool.Initialize();
            IJobStore jobStore = new RAMJobStore();

            CreateScheduler(threadPool, jobStore);
        }
コード例 #5
0
        /// <summary>
        /// Creates an in memory job store (<see cref="RAMJobStore" />)
        /// The thread priority is set to Thread.NORM_PRIORITY
        /// </summary>
        /// <param name="maxThreads">The number of threads in the thread pool</param>
        public virtual void CreateVolatileScheduler(int maxThreads)
        {
            IThreadPool threadPool = new DefaultThreadPool();

            threadPool.Initialize();
            IJobStore jobStore = new RAMJobStore();

            CreateScheduler(threadPool, jobStore);
        }
コード例 #6
0
        /// <summary>
        /// Creates an in memory job store (<see cref="RAMJobStore" />)
        /// </summary>
        /// <param name="maxConcurrency">The number of allowed concurrent running tasks.</param>
        public virtual void CreateVolatileScheduler(int maxConcurrency)
        {
            var threadPool = new DefaultThreadPool
            {
                MaxConcurrency = maxConcurrency
            };

            threadPool.Initialize();
            IJobStore jobStore = new RAMJobStore();

            CreateScheduler(threadPool, jobStore);
        }
コード例 #7
0
        public void Start()
        {
            var configFileNames = string.Join(",", Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory, ConfigName));

            if (string.IsNullOrWhiteSpace(configFileNames))
            {
                return;
            }

            var instanceId = new SimpleInstanceIdGenerator().GenerateInstanceId();

            var threadPool = new SimpleThreadPool(threadCount: 2, threadPriority: ThreadPriority.Normal)
            {
                InstanceName = SchedulerName
            };

            threadPool.Initialize();

            var jobStore = new RAMJobStore
            {
                InstanceName = SchedulerName,
                InstanceId   = instanceId,
            };


            var jobInitializationPlugin = new ConfigFileProcessorPlugin
            {
                FileNames    = configFileNames,
                ScanInterval = QuartzConfigFileScanInterval.DisableScanning
            };

            DirectSchedulerFactory.Instance.CreateScheduler(
                SchedulerName,
                instanceId,
                threadPool,
                jobStore,
                new Dictionary <string, ISchedulerPlugin>
            {
                { SchedulerName, jobInitializationPlugin }
            },
                TimeSpan.Zero,
                TimeSpan.Zero);

            var scheduler = DirectSchedulerFactory.Instance.GetScheduler(SchedulerName);

            scheduler.JobFactory = _jobFactory;

            scheduler.Start();
        }
コード例 #8
0
ファイル: SchedulerFactory.cs プロジェクト: QuantumArt/QA.DPC
        private static IScheduler CreateScheduler(string customerCode)
        {
            var ramJobStore = new RAMJobStore();

            var schedulerResources = new QuartzSchedulerResources
            {
                JobRunShellFactory = new StdJobRunShellFactory(),
                JobStore           = ramJobStore,
                Name = $"TasksScheduler_{customerCode}"
            };

            var threadPool = new DefaultThreadPool();

            threadPool.Initialize();

            schedulerResources.ThreadPool = threadPool;

            var quartzScheduler = new QuartzScheduler(schedulerResources, TimeSpan.Zero);

            ITypeLoadHelper loadHelper;

            try
            {
                loadHelper = ObjectUtils.InstantiateType <ITypeLoadHelper>(typeof(SimpleTypeLoadHelper));
            }
            catch (Exception e)
            {
                throw new SchedulerConfigException("Unable to instantiate type load helper: {0}".FormatInvariant(e.Message), e);
            }

            loadHelper.Initialize();

            ramJobStore.Initialize(loadHelper, quartzScheduler.SchedulerSignaler);

            var standartScheduler = new StdScheduler(quartzScheduler);

            schedulerResources.JobRunShellFactory.Initialize(standartScheduler);

            quartzScheduler.Initialize();

            SchedulerRepository schedRep = SchedulerRepository.Instance;

            schedRep.Bind(standartScheduler);

            return(standartScheduler);
        }
        public void Start()
        {
            var instanceId = new SimpleInstanceIdGenerator().GenerateInstanceId();

            var threadPool = new SimpleThreadPool(threadCount: 2, threadPriority: ThreadPriority.Normal)
            {
                InstanceName = SchedulerName
            };

            threadPool.Initialize();

            var jobstore = new RAMJobStore
            {
                InstanceName = SchedulerName,
                InstanceId   = instanceId,
            };

            var baseUri = new Uri(Assembly.GetExecutingAssembly().GetName().EscapedCodeBase);
            // ReSharper disable once AssignNullToNotNullAttribute
            var fileName = Path.Combine(Path.GetDirectoryName(baseUri.LocalPath), ConfigName);

            var jobInitializationPlugin = new ConfigFileProcessorPlugin
            {
                FileNames    = fileName,
                ScanInterval = QuartzConfigFileScanInterval.DisableScanning
            };

            DirectSchedulerFactory.Instance.CreateScheduler(
                SchedulerName,
                instanceId,
                threadPool,
                jobstore,
                new Dictionary <string, ISchedulerPlugin>
            {
                { SchedulerName, jobInitializationPlugin }
            },
                TimeSpan.Zero,
                TimeSpan.Zero);

            var scheduler = DirectSchedulerFactory.Instance.GetScheduler(SchedulerName);

            scheduler.JobFactory = _jobFactory;

            scheduler.Start();
        }
コード例 #10
0
        public void testStoreAndRetrieveJobs()
        {
            RAMJobStore store = new RAMJobStore();

            // Store jobs.
            for (int i = 0; i < 10; i++)
            {
                IJobDetail job = JobBuilder.Create <NoOpJob>().WithIdentity("job" + i).Build();
                store.StoreJob(job, false);
            }
            // Retrieve jobs.
            for (int i = 0; i < 10; i++)
            {
                JobKey     jobKey    = JobKey.Create("job" + i);
                IJobDetail storedJob = store.RetrieveJob(jobKey);
                Assert.AreEqual(jobKey, storedJob.Key);
            }
        }
コード例 #11
0
        public async Task TestAcquireTriggers()
        {
            ISchedulerSignaler schedSignaler = new SampleSignaler();
            ITypeLoadHelper    loadHelper    = new SimpleTypeLoadHelper();

            loadHelper.Initialize();

            RAMJobStore store = new RAMJobStore();
            await store.Initialize(loadHelper, schedSignaler);

            // Setup: Store jobs and triggers.
            DateTime startTime0 = DateTime.UtcNow.AddMinutes(1).ToUniversalTime(); // a min from now.

            for (int i = 0; i < 10; i++)
            {
                DateTime              startTime = startTime0.AddMinutes(i * 1); // a min apart
                IJobDetail            job       = JobBuilder.Create <NoOpJob>().WithIdentity("job" + i).Build();
                SimpleScheduleBuilder schedule  = SimpleScheduleBuilder.RepeatMinutelyForever(2);
                IOperableTrigger      trigger   = (IOperableTrigger)TriggerBuilder.Create().WithIdentity("job" + i).WithSchedule(schedule).ForJob(job).StartAt(startTime).Build();

                // Manually trigger the first fire time computation that scheduler would do. Otherwise
                // the store.acquireNextTriggers() will not work properly.
                DateTimeOffset?fireTime = trigger.ComputeFirstFireTimeUtc(null);
                Assert.AreEqual(true, fireTime != null);

                await store.StoreJobAndTrigger(job, trigger);
            }

            // Test acquire one trigger at a time
            for (int i = 0; i < 10; i++)
            {
                DateTimeOffset noLaterThan = startTime0.AddMinutes(i);
                int            maxCount    = 1;
                TimeSpan       timeWindow  = TimeSpan.Zero;
                var            triggers    = await store.AcquireNextTriggers(noLaterThan, maxCount, timeWindow);

                Assert.AreEqual(1, triggers.Count);
                var trigger = triggers.First();
                Assert.AreEqual("job" + i, trigger.Key.Name);

                // Let's remove the trigger now.
                await store.RemoveJob(trigger.JobKey);
            }
        }
コード例 #12
0
        public void TestAcquireTriggersInBatch()
        {
            ISchedulerSignaler schedSignaler = new SampleSignaler();
            ITypeLoadHelper    loadHelper    = new SimpleTypeLoadHelper();

            loadHelper.Initialize();

            RAMJobStore store = new RAMJobStore();

            store.Initialize(loadHelper, schedSignaler);

            // Setup: Store jobs and triggers.
            DateTimeOffset startTime0 = DateTimeOffset.UtcNow.AddMinutes(1); // a min from now.

            for (int i = 0; i < 10; i++)
            {
                DateTimeOffset        startTime = startTime0.AddMinutes(i); // a min apart
                IJobDetail            job       = JobBuilder.Create <NoOpJob>().WithIdentity("job" + i).Build();
                SimpleScheduleBuilder schedule  = SimpleScheduleBuilder.RepeatMinutelyForever(2);
                IOperableTrigger      trigger   = (IOperableTrigger)TriggerBuilder.Create().WithIdentity("job" + i).WithSchedule(schedule).ForJob(job).StartAt(startTime).Build();

                // Manually trigger the first fire time computation that scheduler would do. Otherwise
                // the store.acquireNextTriggers() will not work properly.
                DateTimeOffset?fireTime = trigger.ComputeFirstFireTimeUtc(null);
                Assert.AreEqual(true, fireTime != null);

                store.StoreJobAndTrigger(job, trigger);
            }

            // Test acquire batch of triggers at a time
            DateTimeOffset           noLaterThan = startTime0.AddMinutes(10);
            int                      maxCount    = 7;
            TimeSpan                 timeWindow  = TimeSpan.FromMinutes(8);
            IList <IOperableTrigger> triggers    = store.AcquireNextTriggers(noLaterThan, maxCount, timeWindow);

            Assert.AreEqual(7, triggers.Count);
            for (int i = 0; i < 7; i++)
            {
                Assert.AreEqual("job" + i, triggers[i].Key.Name);
            }
        }