首页 > 代码库 > 任务调度之集群(基于Quartz.net)
任务调度之集群(基于Quartz.net)
上一篇我们完成了任务调度的持久化,传送门:任务调度之持久化(基于Quartz.net)
这篇我们来完成Quartz.net的一个比较优秀的功能,即集群;集群可以提高任务调度服务的容灾性,
当一个节点宕机后,其他节点会自动补上去,把超时的Job继续执行下去。
当然了,某个Job同一时刻只会运行在一个节点上,他们是通过数据库锁实现的。
1、集群依赖于数据表
之前2张我们介绍的都是运行在内存上的Job,而集群则一定需要依赖于Quartz.net本身的数据表结构才行
就是这个: enter_db_name_here
1 -- this script is for SQL Server and Azure SQL 2 3 USE [enter_db_name_here] 4 GO 5 6 IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N‘[dbo].[FK_QRTZ_TRIGGERS_QRTZ_JOB_DETAILS]‘) AND OBJECTPROPERTY(id, N‘ISFOREIGNKEY‘) = 1) 7 ALTER TABLE [dbo].[QRTZ_TRIGGERS] DROP CONSTRAINT FK_QRTZ_TRIGGERS_QRTZ_JOB_DETAILS 8 GO 9 10 IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N‘[dbo].[FK_QRTZ_CRON_TRIGGERS_QRTZ_TRIGGERS]‘) AND OBJECTPROPERTY(id, N‘ISFOREIGNKEY‘) = 1) 11 ALTER TABLE [dbo].[QRTZ_CRON_TRIGGERS] DROP CONSTRAINT FK_QRTZ_CRON_TRIGGERS_QRTZ_TRIGGERS 12 GO 13 14 IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N‘[dbo].[FK_QRTZ_SIMPLE_TRIGGERS_QRTZ_TRIGGERS]‘) AND OBJECTPROPERTY(id, N‘ISFOREIGNKEY‘) = 1) 15 ALTER TABLE [dbo].[QRTZ_SIMPLE_TRIGGERS] DROP CONSTRAINT FK_QRTZ_SIMPLE_TRIGGERS_QRTZ_TRIGGERS 16 GO 17 18 IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N‘[dbo].[FK_QRTZ_SIMPROP_TRIGGERS_QRTZ_TRIGGERS]‘) AND OBJECTPROPERTY(id, N‘ISFOREIGNKEY‘) = 1) 19 ALTER TABLE [dbo].[QRTZ_SIMPROP_TRIGGERS] DROP CONSTRAINT FK_QRTZ_SIMPROP_TRIGGERS_QRTZ_TRIGGERS 20 GO 21 22 IF EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N‘[dbo].[FK_QRTZ_JOB_LISTENERS_QRTZ_JOB_DETAILS]‘) AND parent_object_id = OBJECT_ID(N‘[dbo].[QRTZ_JOB_LISTENERS]‘)) 23 ALTER TABLE [dbo].[QRTZ_JOB_LISTENERS] DROP CONSTRAINT [FK_QRTZ_JOB_LISTENERS_QRTZ_JOB_DETAILS] 24 25 IF EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N‘[dbo].[FK_QRTZ_TRIGGER_LISTENERS_QRTZ_TRIGGERS]‘) AND parent_object_id = OBJECT_ID(N‘[dbo].[QRTZ_TRIGGER_LISTENERS]‘)) 26 ALTER TABLE [dbo].[QRTZ_TRIGGER_LISTENERS] DROP CONSTRAINT [FK_QRTZ_TRIGGER_LISTENERS_QRTZ_TRIGGERS] 27 28 29 IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N‘[dbo].[QRTZ_CALENDARS]‘) AND OBJECTPROPERTY(id, N‘ISUSERTABLE‘) = 1) 30 DROP TABLE [dbo].[QRTZ_CALENDARS] 31 GO 32 33 IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N‘[dbo].[QRTZ_CRON_TRIGGERS]‘) AND OBJECTPROPERTY(id, N‘ISUSERTABLE‘) = 1) 34 DROP TABLE [dbo].[QRTZ_CRON_TRIGGERS] 35 GO 36 37 IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N‘[dbo].[QRTZ_BLOB_TRIGGERS]‘) AND OBJECTPROPERTY(id, N‘ISUSERTABLE‘) = 1) 38 DROP TABLE [dbo].[QRTZ_BLOB_TRIGGERS] 39 GO 40 41 IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N‘[dbo].[QRTZ_FIRED_TRIGGERS]‘) AND OBJECTPROPERTY(id, N‘ISUSERTABLE‘) = 1) 42 DROP TABLE [dbo].[QRTZ_FIRED_TRIGGERS] 43 GO 44 45 IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N‘[dbo].[QRTZ_PAUSED_TRIGGER_GRPS]‘) AND OBJECTPROPERTY(id, N‘ISUSERTABLE‘) = 1) 46 DROP TABLE [dbo].[QRTZ_PAUSED_TRIGGER_GRPS] 47 GO 48 49 IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N‘[dbo].[QRTZ_JOB_LISTENERS]‘) AND type in (N‘U‘)) 50 DROP TABLE [dbo].[QRTZ_JOB_LISTENERS] 51 52 IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N‘[dbo].[QRTZ_SCHEDULER_STATE]‘) AND OBJECTPROPERTY(id, N‘ISUSERTABLE‘) = 1) 53 DROP TABLE [dbo].[QRTZ_SCHEDULER_STATE] 54 GO 55 56 IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N‘[dbo].[QRTZ_LOCKS]‘) AND OBJECTPROPERTY(id, N‘ISUSERTABLE‘) = 1) 57 DROP TABLE [dbo].[QRTZ_LOCKS] 58 GO 59 IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N‘[dbo].[QRTZ_TRIGGER_LISTENERS]‘) AND type in (N‘U‘)) 60 DROP TABLE [dbo].[QRTZ_TRIGGER_LISTENERS] 61 62 63 IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N‘[dbo].[QRTZ_JOB_DETAILS]‘) AND OBJECTPROPERTY(id, N‘ISUSERTABLE‘) = 1) 64 DROP TABLE [dbo].[QRTZ_JOB_DETAILS] 65 GO 66 67 IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N‘[dbo].[QRTZ_SIMPLE_TRIGGERS]‘) AND OBJECTPROPERTY(id, N‘ISUSERTABLE‘) = 1) 68 DROP TABLE [dbo].[QRTZ_SIMPLE_TRIGGERS] 69 GO 70 71 IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N‘[dbo].[QRTZ_SIMPROP_TRIGGERS]‘) AND OBJECTPROPERTY(id, N‘ISUSERTABLE‘) = 1) 72 DROP TABLE [dbo].QRTZ_SIMPROP_TRIGGERS 73 GO 74 75 IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N‘[dbo].[QRTZ_TRIGGERS]‘) AND OBJECTPROPERTY(id, N‘ISUSERTABLE‘) = 1) 76 DROP TABLE [dbo].[QRTZ_TRIGGERS] 77 GO 78 79 CREATE TABLE [dbo].[QRTZ_CALENDARS] ( 80 [SCHED_NAME] [NVARCHAR] (100) NOT NULL , 81 [CALENDAR_NAME] [NVARCHAR] (200) NOT NULL , 82 [CALENDAR] [IMAGE] NOT NULL 83 ) 84 GO 85 86 CREATE TABLE [dbo].[QRTZ_CRON_TRIGGERS] ( 87 [SCHED_NAME] [NVARCHAR] (100) NOT NULL , 88 [TRIGGER_NAME] [NVARCHAR] (150) NOT NULL , 89 [TRIGGER_GROUP] [NVARCHAR] (150) NOT NULL , 90 [CRON_EXPRESSION] [NVARCHAR] (120) NOT NULL , 91 [TIME_ZONE_ID] [NVARCHAR] (80) 92 ) 93 GO 94 95 CREATE TABLE [dbo].[QRTZ_FIRED_TRIGGERS] ( 96 [SCHED_NAME] [NVARCHAR] (100) NOT NULL , 97 [ENTRY_ID] [NVARCHAR] (95) NOT NULL , 98 [TRIGGER_NAME] [NVARCHAR] (150) NOT NULL , 99 [TRIGGER_GROUP] [NVARCHAR] (150) NOT NULL ,100 [INSTANCE_NAME] [NVARCHAR] (200) NOT NULL ,101 [FIRED_TIME] [BIGINT] NOT NULL ,102 [SCHED_TIME] [BIGINT] NOT NULL ,103 [PRIORITY] [INTEGER] NOT NULL ,104 [STATE] [NVARCHAR] (16) NOT NULL,105 [JOB_NAME] [NVARCHAR] (150) NULL ,106 [JOB_GROUP] [NVARCHAR] (150) NULL ,107 [IS_NONCONCURRENT] BIT NULL ,108 [REQUESTS_RECOVERY] BIT NULL 109 )110 GO111 112 CREATE TABLE [dbo].[QRTZ_PAUSED_TRIGGER_GRPS] (113 [SCHED_NAME] [NVARCHAR] (100) NOT NULL ,114 [TRIGGER_GROUP] [NVARCHAR] (150) NOT NULL 115 )116 GO117 118 CREATE TABLE [dbo].[QRTZ_SCHEDULER_STATE] (119 [SCHED_NAME] [NVARCHAR] (100) NOT NULL ,120 [INSTANCE_NAME] [NVARCHAR] (200) NOT NULL ,121 [LAST_CHECKIN_TIME] [BIGINT] NOT NULL ,122 [CHECKIN_INTERVAL] [BIGINT] NOT NULL123 )124 GO125 126 CREATE TABLE [dbo].[QRTZ_LOCKS] (127 [SCHED_NAME] [NVARCHAR] (100) NOT NULL ,128 [LOCK_NAME] [NVARCHAR] (40) NOT NULL 129 )130 GO131 132 CREATE TABLE [dbo].[QRTZ_JOB_DETAILS] (133 [SCHED_NAME] [NVARCHAR] (100) NOT NULL ,134 [JOB_NAME] [NVARCHAR] (150) NOT NULL ,135 [JOB_GROUP] [NVARCHAR] (150) NOT NULL ,136 [DESCRIPTION] [NVARCHAR] (250) NULL ,137 [JOB_CLASS_NAME] [NVARCHAR] (250) NOT NULL ,138 [IS_DURABLE] BIT NOT NULL ,139 [IS_NONCONCURRENT] BIT NOT NULL ,140 [IS_UPDATE_DATA] BIT NOT NULL ,141 [REQUESTS_RECOVERY] BIT NOT NULL ,142 [JOB_DATA] [IMAGE] NULL143 )144 GO145 146 CREATE TABLE [dbo].[QRTZ_SIMPLE_TRIGGERS] (147 [SCHED_NAME] [NVARCHAR] (100) NOT NULL ,148 [TRIGGER_NAME] [NVARCHAR] (150) NOT NULL ,149 [TRIGGER_GROUP] [NVARCHAR] (150) NOT NULL ,150 [REPEAT_COUNT] [INTEGER] NOT NULL ,151 [REPEAT_INTERVAL] [BIGINT] NOT NULL ,152 [TIMES_TRIGGERED] [INTEGER] NOT NULL153 )154 GO155 156 CREATE TABLE [dbo].[QRTZ_SIMPROP_TRIGGERS] (157 [SCHED_NAME] [NVARCHAR] (100) NOT NULL ,158 [TRIGGER_NAME] [NVARCHAR] (150) NOT NULL ,159 [TRIGGER_GROUP] [NVARCHAR] (150) NOT NULL ,160 [STR_PROP_1] [NVARCHAR] (512) NULL,161 [STR_PROP_2] [NVARCHAR] (512) NULL,162 [STR_PROP_3] [NVARCHAR] (512) NULL,163 [INT_PROP_1] [INT] NULL,164 [INT_PROP_2] [INT] NULL,165 [LONG_PROP_1] [BIGINT] NULL,166 [LONG_PROP_2] [BIGINT] NULL,167 [DEC_PROP_1] [NUMERIC] (13,4) NULL,168 [DEC_PROP_2] [NUMERIC] (13,4) NULL,169 [BOOL_PROP_1] BIT NULL,170 [BOOL_PROP_2] BIT NULL,171 )172 GO173 174 CREATE TABLE [dbo].[QRTZ_BLOB_TRIGGERS] (175 [SCHED_NAME] [NVARCHAR] (100) NOT NULL ,176 [TRIGGER_NAME] [NVARCHAR] (150) NOT NULL ,177 [TRIGGER_GROUP] [NVARCHAR] (150) NOT NULL ,178 [BLOB_DATA] [IMAGE] NULL179 )180 GO181 182 CREATE TABLE [dbo].[QRTZ_TRIGGERS] (183 [SCHED_NAME] [NVARCHAR] (100) NOT NULL ,184 [TRIGGER_NAME] [NVARCHAR] (150) NOT NULL ,185 [TRIGGER_GROUP] [NVARCHAR] (150) NOT NULL ,186 [JOB_NAME] [NVARCHAR] (150) NOT NULL ,187 [JOB_GROUP] [NVARCHAR] (150) NOT NULL ,188 [DESCRIPTION] [NVARCHAR] (250) NULL ,189 [NEXT_FIRE_TIME] [BIGINT] NULL ,190 [PREV_FIRE_TIME] [BIGINT] NULL ,191 [PRIORITY] [INTEGER] NULL ,192 [TRIGGER_STATE] [NVARCHAR] (16) NOT NULL ,193 [TRIGGER_TYPE] [NVARCHAR] (8) NOT NULL ,194 [START_TIME] [BIGINT] NOT NULL ,195 [END_TIME] [BIGINT] NULL ,196 [CALENDAR_NAME] [NVARCHAR] (200) NULL ,197 [MISFIRE_INSTR] [INTEGER] NULL ,198 [JOB_DATA] [IMAGE] NULL199 )200 GO201 202 ALTER TABLE [dbo].[QRTZ_CALENDARS] WITH NOCHECK ADD203 CONSTRAINT [PK_QRTZ_CALENDARS] PRIMARY KEY CLUSTERED204 (205 [SCHED_NAME],206 [CALENDAR_NAME]207 ) 208 GO209 210 ALTER TABLE [dbo].[QRTZ_CRON_TRIGGERS] WITH NOCHECK ADD211 CONSTRAINT [PK_QRTZ_CRON_TRIGGERS] PRIMARY KEY CLUSTERED212 (213 [SCHED_NAME],214 [TRIGGER_NAME],215 [TRIGGER_GROUP]216 ) 217 GO218 219 ALTER TABLE [dbo].[QRTZ_FIRED_TRIGGERS] WITH NOCHECK ADD220 CONSTRAINT [PK_QRTZ_FIRED_TRIGGERS] PRIMARY KEY CLUSTERED221 (222 [SCHED_NAME],223 [ENTRY_ID]224 ) 225 GO226 227 ALTER TABLE [dbo].[QRTZ_PAUSED_TRIGGER_GRPS] WITH NOCHECK ADD228 CONSTRAINT [PK_QRTZ_PAUSED_TRIGGER_GRPS] PRIMARY KEY CLUSTERED229 (230 [SCHED_NAME],231 [TRIGGER_GROUP]232 ) 233 GO234 235 ALTER TABLE [dbo].[QRTZ_SCHEDULER_STATE] WITH NOCHECK ADD236 CONSTRAINT [PK_QRTZ_SCHEDULER_STATE] PRIMARY KEY CLUSTERED237 (238 [SCHED_NAME],239 [INSTANCE_NAME]240 ) 241 GO242 243 ALTER TABLE [dbo].[QRTZ_LOCKS] WITH NOCHECK ADD244 CONSTRAINT [PK_QRTZ_LOCKS] PRIMARY KEY CLUSTERED245 (246 [SCHED_NAME],247 [LOCK_NAME]248 ) 249 GO250 251 ALTER TABLE [dbo].[QRTZ_JOB_DETAILS] WITH NOCHECK ADD252 CONSTRAINT [PK_QRTZ_JOB_DETAILS] PRIMARY KEY CLUSTERED253 (254 [SCHED_NAME],255 [JOB_NAME],256 [JOB_GROUP]257 ) 258 GO259 260 ALTER TABLE [dbo].[QRTZ_SIMPLE_TRIGGERS] WITH NOCHECK ADD261 CONSTRAINT [PK_QRTZ_SIMPLE_TRIGGERS] PRIMARY KEY CLUSTERED262 (263 [SCHED_NAME],264 [TRIGGER_NAME],265 [TRIGGER_GROUP]266 ) 267 GO268 269 ALTER TABLE [dbo].[QRTZ_SIMPROP_TRIGGERS] WITH NOCHECK ADD270 CONSTRAINT [PK_QRTZ_SIMPROP_TRIGGERS] PRIMARY KEY CLUSTERED271 (272 [SCHED_NAME],273 [TRIGGER_NAME],274 [TRIGGER_GROUP]275 ) 276 GO277 278 ALTER TABLE [dbo].[QRTZ_TRIGGERS] WITH NOCHECK ADD279 CONSTRAINT [PK_QRTZ_TRIGGERS] PRIMARY KEY CLUSTERED280 (281 [SCHED_NAME],282 [TRIGGER_NAME],283 [TRIGGER_GROUP]284 ) 285 GO286 287 ALTER TABLE [dbo].QRTZ_BLOB_TRIGGERS WITH NOCHECK ADD288 CONSTRAINT [PK_QRTZ_BLOB_TRIGGERS] PRIMARY KEY CLUSTERED289 (290 [SCHED_NAME],291 [TRIGGER_NAME],292 [TRIGGER_GROUP]293 ) 294 GO295 296 ALTER TABLE [dbo].[QRTZ_CRON_TRIGGERS] ADD297 CONSTRAINT [FK_QRTZ_CRON_TRIGGERS_QRTZ_TRIGGERS] FOREIGN KEY298 (299 [SCHED_NAME],300 [TRIGGER_NAME],301 [TRIGGER_GROUP]302 ) REFERENCES [dbo].[QRTZ_TRIGGERS] (303 [SCHED_NAME],304 [TRIGGER_NAME],305 [TRIGGER_GROUP]306 ) ON DELETE CASCADE307 GO308 309 ALTER TABLE [dbo].[QRTZ_SIMPLE_TRIGGERS] ADD310 CONSTRAINT [FK_QRTZ_SIMPLE_TRIGGERS_QRTZ_TRIGGERS] FOREIGN KEY311 (312 [SCHED_NAME],313 [TRIGGER_NAME],314 [TRIGGER_GROUP]315 ) REFERENCES [dbo].[QRTZ_TRIGGERS] (316 [SCHED_NAME],317 [TRIGGER_NAME],318 [TRIGGER_GROUP]319 ) ON DELETE CASCADE320 GO321 322 ALTER TABLE [dbo].[QRTZ_SIMPROP_TRIGGERS] ADD323 CONSTRAINT [FK_QRTZ_SIMPROP_TRIGGERS_QRTZ_TRIGGERS] FOREIGN KEY324 (325 [SCHED_NAME],326 [TRIGGER_NAME],327 [TRIGGER_GROUP]328 ) REFERENCES [dbo].[QRTZ_TRIGGERS] (329 [SCHED_NAME],330 [TRIGGER_NAME],331 [TRIGGER_GROUP]332 ) ON DELETE CASCADE333 GO334 335 ALTER TABLE [dbo].[QRTZ_TRIGGERS] ADD336 CONSTRAINT [FK_QRTZ_TRIGGERS_QRTZ_JOB_DETAILS] FOREIGN KEY337 (338 [SCHED_NAME],339 [JOB_NAME],340 [JOB_GROUP]341 ) REFERENCES [dbo].[QRTZ_JOB_DETAILS] (342 [SCHED_NAME],343 [JOB_NAME],344 [JOB_GROUP]345 )346 GO347 348 CREATE INDEX IDX_QRTZ_T_J ON QRTZ_TRIGGERS(SCHED_NAME,JOB_NAME,JOB_GROUP)349 CREATE INDEX IDX_QRTZ_T_JG ON QRTZ_TRIGGERS(SCHED_NAME,JOB_GROUP)350 CREATE INDEX IDX_QRTZ_T_C ON QRTZ_TRIGGERS(SCHED_NAME,CALENDAR_NAME)351 CREATE INDEX IDX_QRTZ_T_G ON QRTZ_TRIGGERS(SCHED_NAME,TRIGGER_GROUP)352 CREATE INDEX IDX_QRTZ_T_STATE ON QRTZ_TRIGGERS(SCHED_NAME,TRIGGER_STATE)353 CREATE INDEX IDX_QRTZ_T_N_STATE ON QRTZ_TRIGGERS(SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP,TRIGGER_STATE)354 CREATE INDEX IDX_QRTZ_T_N_G_STATE ON QRTZ_TRIGGERS(SCHED_NAME,TRIGGER_GROUP,TRIGGER_STATE)355 CREATE INDEX IDX_QRTZ_T_NEXT_FIRE_TIME ON QRTZ_TRIGGERS(SCHED_NAME,NEXT_FIRE_TIME)356 CREATE INDEX IDX_QRTZ_T_NFT_ST ON QRTZ_TRIGGERS(SCHED_NAME,TRIGGER_STATE,NEXT_FIRE_TIME)357 CREATE INDEX IDX_QRTZ_T_NFT_MISFIRE ON QRTZ_TRIGGERS(SCHED_NAME,MISFIRE_INSTR,NEXT_FIRE_TIME)358 CREATE INDEX IDX_QRTZ_T_NFT_ST_MISFIRE ON QRTZ_TRIGGERS(SCHED_NAME,MISFIRE_INSTR,NEXT_FIRE_TIME,TRIGGER_STATE)359 CREATE INDEX IDX_QRTZ_T_NFT_ST_MISFIRE_GRP ON QRTZ_TRIGGERS(SCHED_NAME,MISFIRE_INSTR,NEXT_FIRE_TIME,TRIGGER_GROUP,TRIGGER_STATE)360 361 CREATE INDEX IDX_QRTZ_FT_TRIG_INST_NAME ON QRTZ_FIRED_TRIGGERS(SCHED_NAME,INSTANCE_NAME)362 CREATE INDEX IDX_QRTZ_FT_INST_JOB_REQ_RCVRY ON QRTZ_FIRED_TRIGGERS(SCHED_NAME,INSTANCE_NAME,REQUESTS_RECOVERY)363 CREATE INDEX IDX_QRTZ_FT_J_G ON QRTZ_FIRED_TRIGGERS(SCHED_NAME,JOB_NAME,JOB_GROUP)364 CREATE INDEX IDX_QRTZ_FT_JG ON QRTZ_FIRED_TRIGGERS(SCHED_NAME,JOB_GROUP)365 CREATE INDEX IDX_QRTZ_FT_T_G ON QRTZ_FIRED_TRIGGERS(SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP)366 CREATE INDEX IDX_QRTZ_FT_TG ON QRTZ_FIRED_TRIGGERS(SCHED_NAME,TRIGGER_GROUP)367 GO
直接创建数据库运行就好了,至于表结构用途请百度
2、修改JobServer
RemoteServer.cs,即上篇的那个服务端的类
1 properties["quartz.jobStore.clustered"] = "true";2 properties["quartz.jobStore.type"] = "Quartz.Impl.AdoJobStore.JobStoreTX, Quartz";3 properties["quartz.jobStore.tablePrefix"] = "QRTZ_";4 properties["quartz.jobStore.driverDelegateType"] = "Quartz.Impl.AdoJobStore.SqlServerDelegate, Quartz";5 properties["quartz.jobStore.dataSource"] = "myDS";6 properties["quartz.dataSource.myDS.connectionString"] = @"Data Source=JIANRONGLAN-PC\SQLEXPRESS;Initial Catalog=SystemBase;User ID=sa;Password=123456";7 properties["quartz.dataSource.myDS.provider"] = "SqlServer-20";
参数初始化中加上上边的参数就可以了,其他不用改
3、远端控制界面
MVC的控制界面有改动,上一篇我们是新建了一个Job表,包含很多字段,但是现在加入组件本身的表结构,那Job有些字段就点多余;
所以我把时间和状态字段删掉了,新Job
1 public class Job 2 { 3 [IgnoreProperty(true)] 4 public int RowNumber { get; set; } 5 6 /// <summary>Id</summary> 7 public Guid Id { get; set; } 8 9 /// <summary>GroupName</summary>10 public string GroupName { get; set; }11 12 /// <summary>JobName</summary>13 public string JobName { get; set; }14 15 /// <summary>TriggerName</summary>16 public string TriggerName { get; set; }17 18 /// <summary>Cron</summary>19 public string Cron { get; set; }20 21 /// <summary>Description</summary>22 public string Description { get; set; }23 24 /// <summary>CreateTime</summary> 25 public DateTime CreateTime { get; set; }26 }
然后列表查询的时候直接关联QRTZ_TRIGGERS 就好了,我们来看看效果
4、部署Quartz节点
4.1 拷贝JobServer,运行JobServer.exe,分别是128/129
好了,现在2个机器服务端都在等待状态了
4.2、控制端开启任务
4.3、看到分配到129运行了,最后执行时间是23:45:15,这是128还是等等状态的。然后关闭129的JobServer
4.4、128开始运行,看到128在23:46:42才开始运行
好了,集群就这么多点东西,很简单的,搭建环境还比较麻烦
任务调度之集群(基于Quartz.net)
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。