码迷,mamicode.com
首页 > Web开发 > 详细

任务调度之集群(基于Quartz.net)

时间:2017-03-29 00:45:14      阅读:326      评论:0      收藏:0      [点我收藏+]

标签:sts   prefix   exists   tor   art   interval   type   sum   char   

上一篇我们完成了任务调度的持久化,传送门:任务调度之持久化(基于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, NISFOREIGNKEY) = 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, NISFOREIGNKEY) = 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, NISFOREIGNKEY) = 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, NISFOREIGNKEY) = 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, NISUSERTABLE) = 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, NISUSERTABLE) = 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, NISUSERTABLE) = 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, NISUSERTABLE) = 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, NISUSERTABLE) = 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 (NU))
 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, NISUSERTABLE) = 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, NISUSERTABLE) = 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 (NU))
 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, NISUSERTABLE) = 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, NISUSERTABLE) = 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, NISUSERTABLE) = 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, NISUSERTABLE) = 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 GO
111 
112 CREATE TABLE [dbo].[QRTZ_PAUSED_TRIGGER_GRPS] (
113   [SCHED_NAME] [NVARCHAR] (100)  NOT NULL ,
114   [TRIGGER_GROUP] [NVARCHAR] (150)  NOT NULL 
115 )
116 GO
117 
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 NULL
123 )
124 GO
125 
126 CREATE TABLE [dbo].[QRTZ_LOCKS] (
127   [SCHED_NAME] [NVARCHAR] (100)  NOT NULL ,
128   [LOCK_NAME] [NVARCHAR] (40)  NOT NULL 
129 )
130 GO
131 
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] NULL
143 )
144 GO
145 
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 NULL
153 )
154 GO
155 
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 GO
173 
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] NULL
179 )
180 GO
181 
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] NULL
199 )
200 GO
201 
202 ALTER TABLE [dbo].[QRTZ_CALENDARS] WITH NOCHECK ADD
203   CONSTRAINT [PK_QRTZ_CALENDARS] PRIMARY KEY  CLUSTERED
204   (
205     [SCHED_NAME],
206     [CALENDAR_NAME]
207   ) 
208 GO
209 
210 ALTER TABLE [dbo].[QRTZ_CRON_TRIGGERS] WITH NOCHECK ADD
211   CONSTRAINT [PK_QRTZ_CRON_TRIGGERS] PRIMARY KEY  CLUSTERED
212   (
213     [SCHED_NAME],
214     [TRIGGER_NAME],
215     [TRIGGER_GROUP]
216   ) 
217 GO
218 
219 ALTER TABLE [dbo].[QRTZ_FIRED_TRIGGERS] WITH NOCHECK ADD
220   CONSTRAINT [PK_QRTZ_FIRED_TRIGGERS] PRIMARY KEY  CLUSTERED
221   (
222     [SCHED_NAME],
223     [ENTRY_ID]
224   ) 
225 GO
226 
227 ALTER TABLE [dbo].[QRTZ_PAUSED_TRIGGER_GRPS] WITH NOCHECK ADD
228   CONSTRAINT [PK_QRTZ_PAUSED_TRIGGER_GRPS] PRIMARY KEY  CLUSTERED
229   (
230     [SCHED_NAME],
231     [TRIGGER_GROUP]
232   ) 
233 GO
234 
235 ALTER TABLE [dbo].[QRTZ_SCHEDULER_STATE] WITH NOCHECK ADD
236   CONSTRAINT [PK_QRTZ_SCHEDULER_STATE] PRIMARY KEY  CLUSTERED
237   (
238     [SCHED_NAME],
239     [INSTANCE_NAME]
240   ) 
241 GO
242 
243 ALTER TABLE [dbo].[QRTZ_LOCKS] WITH NOCHECK ADD
244   CONSTRAINT [PK_QRTZ_LOCKS] PRIMARY KEY  CLUSTERED
245   (
246     [SCHED_NAME],
247     [LOCK_NAME]
248   ) 
249 GO
250 
251 ALTER TABLE [dbo].[QRTZ_JOB_DETAILS] WITH NOCHECK ADD
252   CONSTRAINT [PK_QRTZ_JOB_DETAILS] PRIMARY KEY  CLUSTERED
253   (
254     [SCHED_NAME],
255     [JOB_NAME],
256     [JOB_GROUP]
257   ) 
258 GO
259 
260 ALTER TABLE [dbo].[QRTZ_SIMPLE_TRIGGERS] WITH NOCHECK ADD
261   CONSTRAINT [PK_QRTZ_SIMPLE_TRIGGERS] PRIMARY KEY  CLUSTERED
262   (
263     [SCHED_NAME],
264     [TRIGGER_NAME],
265     [TRIGGER_GROUP]
266   ) 
267 GO
268 
269 ALTER TABLE [dbo].[QRTZ_SIMPROP_TRIGGERS] WITH NOCHECK ADD
270   CONSTRAINT [PK_QRTZ_SIMPROP_TRIGGERS] PRIMARY KEY  CLUSTERED
271   (
272     [SCHED_NAME],
273     [TRIGGER_NAME],
274     [TRIGGER_GROUP]
275   ) 
276 GO
277 
278 ALTER TABLE [dbo].[QRTZ_TRIGGERS] WITH NOCHECK ADD
279   CONSTRAINT [PK_QRTZ_TRIGGERS] PRIMARY KEY  CLUSTERED
280   (
281     [SCHED_NAME],
282     [TRIGGER_NAME],
283     [TRIGGER_GROUP]
284   ) 
285 GO
286 
287 ALTER TABLE [dbo].QRTZ_BLOB_TRIGGERS WITH NOCHECK ADD
288   CONSTRAINT [PK_QRTZ_BLOB_TRIGGERS] PRIMARY KEY  CLUSTERED
289   (
290     [SCHED_NAME],
291     [TRIGGER_NAME],
292     [TRIGGER_GROUP]
293   ) 
294 GO
295 
296 ALTER TABLE [dbo].[QRTZ_CRON_TRIGGERS] ADD
297   CONSTRAINT [FK_QRTZ_CRON_TRIGGERS_QRTZ_TRIGGERS] FOREIGN KEY
298   (
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 CASCADE
307 GO
308 
309 ALTER TABLE [dbo].[QRTZ_SIMPLE_TRIGGERS] ADD
310   CONSTRAINT [FK_QRTZ_SIMPLE_TRIGGERS_QRTZ_TRIGGERS] FOREIGN KEY
311   (
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 CASCADE
320 GO
321 
322 ALTER TABLE [dbo].[QRTZ_SIMPROP_TRIGGERS] ADD
323   CONSTRAINT [FK_QRTZ_SIMPROP_TRIGGERS_QRTZ_TRIGGERS] FOREIGN KEY
324   (
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 CASCADE
333 GO
334 
335 ALTER TABLE [dbo].[QRTZ_TRIGGERS] ADD
336   CONSTRAINT [FK_QRTZ_TRIGGERS_QRTZ_JOB_DETAILS] FOREIGN KEY
337   (
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 GO
347 
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
View Code

直接创建数据库运行就好了,至于表结构用途请百度

 

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)

标签:sts   prefix   exists   tor   art   interval   type   sum   char   

原文地址:http://www.cnblogs.com/lanxiaoke/p/6637714.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!