/// <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); }
public async void Initialize() { _generalPool = new DefaultThreadPool(); _generalPool.MaxConcurency = AppConfiguration.Instance.MaxConcurencyThreadPool; _generalPool.Initialize(); DirectSchedulerFactory .Instance .CreateScheduler("General Scheduler", "GeneralScheduler", _generalPool, new RAMJobStore()); _generalScheduler = await DirectSchedulerFactory.Instance.GetScheduler("General Scheduler"); }
/// <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); }
public async Task <IScheduler> GetScheduler() { LogProvider.SetCurrentLogProvider(new QuartzLogProvider()); IScheduler _scheduler; string driverDelegateType; var db = Configuration.GetSection("DB").Value; switch (db) { case "MsSql": DBConnectionManager.Instance.AddConnectionProvider("default", new DbProvider("SqlServer", Configuration["ConnectionStrings:MsSqlConnection"])); driverDelegateType = typeof(SqlServerDelegate).AssemblyQualifiedName; break; case "MySql": DBConnectionManager.Instance.AddConnectionProvider("default", new DbProvider("MySql", Configuration["ConnectionStrings:MySqlConnection"])); driverDelegateType = typeof(MySQLDelegate).AssemblyQualifiedName; break; default: DBConnectionManager.Instance.AddConnectionProvider("default", new DbProvider("SqlServer", Configuration["ConnectionStrings:MsSqlConnection"])); driverDelegateType = typeof(SqlServerDelegate).AssemblyQualifiedName; break; } var serializer = new JsonObjectSerializer(); serializer.Initialize(); var jobStore = new JobStoreTX { DataSource = "default", TablePrefix = "QRTZ_", InstanceId = "AUTO", DriverDelegateType = driverDelegateType ?? string.Empty, //SQLServer存储 ObjectSerializer = serializer, //Clustered = true, //集群标志 //AcquireTriggersWithinLock = true, //如果是集群 建议设为true InstanceName = "Lion", }; var threadPool = new DefaultThreadPool { ThreadCount = 20, }; DirectSchedulerFactory.Instance.CreateScheduler("Scheduler", "AUTO", threadPool, jobStore); _scheduler = await SchedulerRepository.Instance.Lookup("Scheduler"); _scheduler.ListenerManager.AddJobListener(new MyJobListener(), GroupMatcher <JobKey> .AnyGroup()); //_scheduler.ListenerManager.AddTriggerListener(new MyTriggerListener(), GroupMatcher<TriggerKey>.AnyGroup()); _scheduler.ListenerManager.AddSchedulerListener(new MySchedulerListener()); return(_scheduler); }
/// <summary> /// 创建一个scheduler(自定义调度器的相关参数) /// </summary> /// <param name="schedulerConfig"></param> public bool CreateScheduler(SchedulerConfig schedulerConfig) { try { var pool = new DefaultThreadPool() { ThreadCount = schedulerConfig.ThreadCount }; _factory.CreateScheduler(schedulerConfig.SchedulerName, schedulerConfig.SchedulerId, pool, new RAMJobStore()); return(true); } catch (Exception ex) { return(false); } }
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); }