public void WillExecuteAtServerInitialization()
        {
            var scheduleFactory  = new StdSchedulerFactory();
            var getJobCalled     = false;
            var mockedJobService = new Mock <IJobService>();

            mockedJobService
            .Setup(x => x.Get())
            .Callback(() => getJobCalled = true)
            .Returns(new List <Job>()
            {
                new Job()
                {
                    Configuration = new SimpleConfig()
                }
            });
            var updateJob = new UpdateInMemoryQuartzJob(new IConfigurableJob[] { new SimpleJob(mockedJobService.Object), }, mockedJobService.Object, scheduleFactory);

            var mockedFactory = new Mock <IJobFactory>(MockBehavior.Default);

            mockedFactory
            .Setup(x => x.NewJob(It.IsAny <TriggerFiredBundle>(), It.IsAny <IScheduler>()))
            .Returns(updateJob);

            var server = new QuartzServer(mockedFactory.Object, new GlobalJobListener(), scheduleFactory, new [] { updateJob });

            server.Initialize();

            getJobCalled.Should().BeTrue();
        }
Beispiel #2
0
        private static void SetScheduledJobs(QuartzServer server, IList <Type> implementedJobs)
        {
            var jobConfigDetailsRepository = new Repository <JobConfigurationDetails>();

            foreach (var implementedJob in implementedJobs)
            {
                var jobConfiguration = jobConfigDetailsRepository.GetAll().FirstOrDefault(x => x.Name == implementedJob.Name);
                if (jobConfiguration != null)
                {
                    IJobDetail job     = JobBuilder.Create(implementedJob).WithIdentity(implementedJob.Name, "group1").Build();
                    ITrigger   trigger = TriggerBuilder.Create()
                                         .WithIdentity(implementedJob.Name + "trigger", "group1")
                                         .StartNow()
                                         .WithSimpleSchedule(x => x
                                                             .WithIntervalInSeconds((int)jobConfiguration.TriggerTimeInSec)
                                                             .RepeatForever())
                                         .Build();

                    server.Scheduler.ScheduleJob(job, trigger);
                }
                else
                {
                    _log.DebugFormat("Job was not configured in db. JobName={0}", implementedJob.Name);
                }
            }
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            var exiteCode = HostFactory.Run(x =>
            {
                x.Service <IQuartzServer>(s =>
                {
                    s.ConstructUsing(name =>
                    {
                        QuartzServer server = new QuartzServer();
                        server.Initialize();
                        return(server);
                    });
                    s.WhenStarted(server => server.Start());
                    s.WhenPaused(server => server.Pause());
                    s.WhenContinued(server => server.Resume());
                    s.WhenStopped(server => server.Stop());
                });

                x.RunAsLocalSystem();

                x.SetDescription("Quartz.Net Server");
                x.SetDisplayName("Quartz.Net Server");
                x.SetServiceName("Quartz.NetServer");
            });
        }
Beispiel #4
0
        static void Main(string[] args)
        {
            Directory.SetCurrentDirectory(System.AppDomain.CurrentDomain.BaseDirectory);

            HostFactory.Run(x =>
            {
                x.RunAsLocalSystem();

                x.SetDescription(QuartzServerConfig.ServiceDescription);
                x.SetDisplayName(QuartzServerConfig.ServiceDisplayName);
                x.SetServiceName(QuartzServerConfig.ServiceName);
                x.SetStartTimeout(new TimeSpan(0, 0, 120));
                x.EnableServiceRecovery(r =>
                {
                    r.RestartService(0);
                    r.RestartService(0);
                    r.RestartService(0);
                    r.OnCrashOnly();
                });

                x.Service(factory =>
                {
                    QuartzServer server = new QuartzServer();
                    return(server);
                });
            });
        }
Beispiel #5
0
        static void Main(string[] args)
        {
            log4net.Config.XmlConfigurator.Configure();
            _log.DebugFormat("Program was started");
            var server = new QuartzServer();

            server.Initialize();
            var implementedJobs = new JobProvider().GetImplementedJobsTypes();

            SetScheduledJobs(server, implementedJobs);
        }
 /// <summary>
 /// Main.
 /// </summary>
 public static void Main()
 {
     HostFactory.Run(x =>
     {
         x.RunAsLocalSystem();
         x.SetDescription(Configuration.ServiceDescription);
         x.SetDisplayName(Configuration.ServiceDisplayName);
         x.SetServiceName(Configuration.ServiceName);
         x.Service(factory =>
         {
             QuartzServer server = new QuartzServer();
             server.Initialize();
             return(server);
         });
     });
 }
Beispiel #7
0
        public static void Run()
        {
            HostFactory.Run(x =>
            {
                x.RunAsLocalSystem();

                x.SetDescription(UtilHelper.GetAppSetting("ZcbListening_ServiceName"));
                x.SetDisplayName(UtilHelper.GetAppSetting("ZcbListening_ServiceDisplayName"));
                x.SetServiceName(UtilHelper.GetAppSetting("ZcbListening_ServiceDescription"));

                x.Service(factory =>
                {
                    var server = new QuartzServer();
                    server.Initialize();

                    return(server);
                });
            });
        }
        public void WillScheduleJob()
        {
            var getJobCalled    = false;
            var schedulerCalled = false;
            var scheduleFactory = new Mock <ISchedulerFactory>();
            var scheduler       = new StdSchedulerFactory().GetScheduler();

            scheduleFactory.Setup(x => x.GetScheduler(It.IsAny <CancellationToken>()))
            .Callback(() => schedulerCalled = true)
            .Returns(scheduler);

            var mockedJobService = new Mock <IJobService>();

            mockedJobService
            .Setup(x => x.Get())
            .Callback(() => getJobCalled = true)
            .Returns(new List <Job>()
            {
                new Job()
                {
                    Configuration = new SimpleConfig(), LastUpdated = DateTime.Now, Name = "test", TriggerCronSyntax = "*/4 * * * * ?"
                }
            });
            var updateJob = new UpdateInMemoryQuartzJob(
                new IConfigurableJob[] { new SimpleJob(mockedJobService.Object), },
                mockedJobService.Object, scheduleFactory.Object);

            var mockedFactory = new Mock <IJobFactory>(MockBehavior.Default);

            mockedFactory
            .Setup(x => x.NewJob(It.IsAny <TriggerFiredBundle>(), It.IsAny <IScheduler>()))
            .Returns(updateJob);

            var server = new QuartzServer(mockedFactory.Object, new GlobalJobListener(), scheduleFactory.Object, new[] { updateJob });

            server.Initialize();

            getJobCalled.Should().BeTrue();
            schedulerCalled.Should().BeTrue();
        }
        /// <summary>
        /// Main.
        /// </summary>
        public static void Main(string[] args)
        {
            // change from service account's dir to more logical one
            Directory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory);

            // TODO: Add DI config
            // TODO: Add Logger Config

            HostFactory.Run(x => {
                x.RunAsLocalSystem();

                x.SetDescription(Configuration.ServiceDescription);
                x.SetDisplayName(Configuration.ServiceDisplayName);
                x.SetServiceName(Configuration.ServiceName);

                x.Service(factory => {
                    QuartzServer server = QuartzServerFactory.CreateServer();
                    server.Initialize().GetAwaiter().GetResult();
                    return(server);
                });
            });
        }
Beispiel #10
0
        /// <summary>
        /// 添加Quartz服务
        /// </summary>
        /// <param name="services"></param>
        /// <param name="props">属性</param>
        /// <returns></returns>
        public static IServiceCollection AddQuartz(this IServiceCollection services, NameValueCollection props)
        {
            #region ==反射注入所有模块的任务服务==

            var modules = services.BuildServiceProvider().GetService <IModuleCollection>();
            if (modules != null && modules.Any())
            {
                foreach (var module in modules)
                {
                    var quartzAssembly = module.AssemblyDescriptor.Quartz;
                    if (quartzAssembly != null)
                    {
                        var jobTypes = quartzAssembly.GetTypes().Where(m => typeof(IJobTask).IsAssignableFrom(m));
                        foreach (var jobType in jobTypes)
                        {
                            services.AddTransient(jobType);
                        }
                    }
                }
            }

            #endregion

            //注入日志
            services.TryAddTransient <IJobLogger, JobLogger>();

            var sp     = services.BuildServiceProvider();
            var logger = sp.GetService <ILogger <QuartzServer> >();
            var server = new QuartzServer(sp, props, logger);
            server.Start().Wait();

            //注入Quartz服务
            services.AddSingleton <IQuartzServer>(server);

            //注入应用关闭事件
            services.AddSingleton <IAppShutdownHandler, QuartzAppShutdownHandler>();

            return(services);
        }
Beispiel #11
0
        /// <summary>
        /// Main.
        /// </summary>
        public static void Main()
        {
            //Install-Package Common.Logging.Log4Net1213 -Version 3.0.0
            //Install-Package log4net
            HostFactory.Run(x =>
            {
                x.RunAsLocalSystem();

                x.SetDescription(Configuration.ServiceDescription);
                x.SetDisplayName(Configuration.ServiceDisplayName);
                x.SetServiceName(Configuration.ServiceName);

                x.Service(factory =>
                {
                    Directory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory);

                    QuartzServer server = new QuartzServer();
                    server.Initialize();
                    return(server);
                });
            });
        }