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); } }
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)); }
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>(); } }
public async Task <ActionResult> Local() { await CreateJob(QuartzConfiguration.LocalConfig(false), "local", true); return(View("Index")); }
public async Task <ActionResult> Remote() { await CreateJob(QuartzConfiguration.RemoteConfig(), "remote", false); return(View("Index")); }