Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            try
            {
                Task.Run(async() =>
                {
                    StdSchedulerFactory factory = new StdSchedulerFactory(QuartzConfiguration.LocalConfig(false));

                    // get a scheduler
                    IScheduler sched = await factory.GetScheduler();

                    if (!sched.IsStarted)
                    {
                        await sched.Start();
                    }

                    Console.WriteLine("Local Server has been started..");

                    while (true)
                    {
                        Thread.Sleep(60 * 60000);
                    }
                }).Wait();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }
Ejemplo n.º 2
0
        public QuartzHostedService(IJobFactory jobFactory, ILogger <QuartzHostedService> logger)
        {
            var appSettings = Singleton <AppSettings> .Instance;

            _quartzConfig = appSettings.ModuleConfigurations[nameof(QuartzConfiguration)] as QuartzConfiguration;
            _logger       = logger ?? throw new ArgumentNullException(nameof(logger));
            _jobFactory   = jobFactory ?? throw new ArgumentNullException(nameof(jobFactory));
        }
Ejemplo n.º 3
0
        public static void AddQuartzHosted(this IServiceCollection services, QuartzConfiguration configuration)
        {
            services.AddTransient <ISchedulerFactory, StdSchedulerFactory>();
            services.AddTransient <IJobFactory, SingletonJobFactory>();
            var tasks = configuration.Tasks.Where(x => x.Enabled).ToList();

            foreach (var task in configuration.Tasks.Where(x => x.Enabled).ToList())
            {
                var jobType = Type.GetType(task.Type);
                if (jobType != null)
                {
                    services.AddTransient(jobType);
                }
            }

            if (tasks.Any())
            {
                services.AddTransient <IHostedService, QuartzHostedService>();
            }
        }
Ejemplo n.º 4
0
        public async Task <ActionResult> Local()
        {
            await CreateJob(QuartzConfiguration.LocalConfig(false), "local", true);

            return(View("Index"));
        }
Ejemplo n.º 5
0
        public async Task <ActionResult> Remote()
        {
            await CreateJob(QuartzConfiguration.RemoteConfig(), "remote", false);

            return(View("Index"));
        }