首页 新闻 搜索 专区 学院

quartz任务调度怎么实现远程控制Job,麻烦大哥大嫂帮忙看下

0
悬赏园豆:5 [已关闭问题] 关闭于 2015-11-19 16:54

刚毕业,组长就叫我自己搞个任务调度管理系统;

自己简单搞了个命令行的,好像不行,麻烦大哥大嫂帮忙看下

 1 public class RemoteClientExample
 2     {
 3         public virtual void Run()
 4         {
 5             ILog log = LogManager.GetLogger(typeof(RemoteClientExample));
 6 
 7             NameValueCollection properties = new NameValueCollection();
 8             properties["quartz.scheduler.instanceName"] = "RemoteClient";
 9 
10             // set thread pool info
11             properties["quartz.threadPool.type"] = "Quartz.Simpl.SimpleThreadPool, Quartz";
12             properties["quartz.threadPool.threadCount"] = "5";
13             properties["quartz.threadPool.threadPriority"] = "Normal";
14 
15             // set remoting exporter
16             properties["quartz.scheduler.proxy"] = "true";
17             properties["quartz.scheduler.proxy.address"] = "tcp://127.0.0.1:555/QuartzScheduler";
18 
19             // First we must get a reference to a scheduler
20             ISchedulerFactory sf = new StdSchedulerFactory(properties);
21             IScheduler sched = sf.GetScheduler();
22 
23             // define the job and ask it to run
24 
25             IJobDetail job = JobBuilder.Create<SimpleJob>()
26                 .WithIdentity("remotelyAddedJob", "default")
27                 .Build();
28 
29             JobDataMap map = job.JobDataMap;
30             map.Put("msg", "Your remotely added job has executed!");
31 
32             ITrigger trigger = TriggerBuilder.Create()
33                 .WithIdentity("remotelyAddedTrigger", "default")
34                 .ForJob(job.Key)
35                 .WithCronSchedule("/5 * * ? * *")
36                 .Build();
37 
38             // schedule the job
39             sched.ScheduleJob(job, trigger);
40 
41             Console.WriteLine("Remote job scheduled.");
42             //log.Info("Remote job scheduled.");
43         }
44 
45         public string Name
46         {
47             get { return null; }
48         }
49     }

 

 1 public class RemoteServerExample
 2     {
 3         public string Name
 4         {
 5             get { return GetType().Name; }
 6         }
 7 
 8         /// <summary>
 9         /// This example will start a server that will allow clients to remotely schedule jobs.
10         /// </summary>
11         /// <author>  James House, Bill Kratzer
12         /// </author>
13         public virtual void Run()
14         {
15             ILog log = LogManager.GetLogger(typeof(RemoteServerExample));
16 
17             NameValueCollection properties = new NameValueCollection();
18             properties["quartz.scheduler.instanceName"] = "RemoteServer";
19 
20             // set thread pool info
21             properties["quartz.threadPool.type"] = "Quartz.Simpl.SimpleThreadPool, Quartz";
22             properties["quartz.threadPool.threadCount"] = "5";
23             properties["quartz.threadPool.threadPriority"] = "Normal";
24 
25             // set remoting exporter
26             properties["quartz.scheduler.exporter.type"] = "Quartz.Simpl.RemotingSchedulerExporter, Quartz";
27             properties["quartz.scheduler.exporter.port"] = "555";
28             properties["quartz.scheduler.exporter.bindName"] = "QuartzScheduler";
29             properties["quartz.scheduler.exporter.channelType"] = "tcp";
30             properties["quartz.scheduler.exporter.channelName"] = "httpQuartz";
31             // reject non-local requests
32             properties["quartz.scheduler.exporter.rejectRemoteRequests"] = "true";
33 
34             ISchedulerFactory sf = new StdSchedulerFactory(properties);
35             IScheduler sched = sf.GetScheduler();
36 
37             Console.WriteLine("------- Initialization Complete -----------");
38             Console.WriteLine("------- Not scheduling any Jobs - relying on a remote client to schedule jobs --");
39             Console.WriteLine("------- Starting Scheduler ----------------");
40             //log.Info("------- Initialization Complete -----------");
41 
42             //log.Info("------- Not scheduling any Jobs - relying on a remote client to schedule jobs --");
43 
44             //log.Info("------- Starting Scheduler ----------------");
45 
46             // start the schedule
47             sched.Start();
48 
49             Console.WriteLine("------- Starting Scheduler ----------------");
50             //Console.WriteLine("------- Waiting 5 minutes... ------------");
51 
52             //log.Info("------- Started Scheduler -----------------");
53 
54             //log.Info("------- Waiting 5 minutes... ------------");
55 
56             // wait to give our jobs a chance to run
57             try
58             {
59                 Thread.Sleep(TimeSpan.FromMilliseconds(2000));
60             }
61             catch (ThreadInterruptedException)
62             {
63             }
64 
65             Console.WriteLine("------- Shutting Down ---------------------");
66             // shut down the scheduler
67             //log.Info("------- Shutting Down ---------------------");
68 
69             //sched.Shutdown(true);
70 
71             //log.Info("------- Shutdown Complete -----------------");
72             Console.WriteLine("------- Shutdown Complete -----------------");
73 
74             SchedulerMetaData metaData = sched.GetMetaData();
75             //log.Info("Executed " + metaData.NumberOfJobsExecuted + " jobs.");
76             Console.WriteLine("Executed " + metaData.NumberOfJobsExecuted + " jobs.");
77         }
78 
79     }

 

 1 class Program
 2     {
 3         static void Main(string[] args)
 4         {
 5             RemoteClientExample clientExample = new RemoteClientExample();
 6 
 7             RemoteServerExample serverExample = new RemoteServerExample();
 8 
 9             serverExample.Run();
10             clientExample.Run();
11             
12 
13             Console.Read();
14         }
15     }

1.怎么远程启动它?

2.并且经常出现:Scheduler with name 'RemoteServer' already exists.?

反骨仔的主页 反骨仔 | 菜鸟二级 | 园豆:444
提问于:2015-11-17 10:31
< >
分享
所有回答(1)
1

1、调度服务server端一般放到服务器上 , 启动直接在服务器上启动就行了(他是一直运行的 也不需要每天都启动)

     如果非要远程启动 你可以写个网页放服务器上(比如 点击网页上某个按钮就启动或停止你那个Server控制台exe程序)。

2、经常出现:Scheduler with name 'RemoteServer' already exists.的原因 应该是你开着那个Server控制台exe程序的时候 又打开另外一个 的原因吧 “RemoteServer” 实例已存在 所以会报错。

clarlespeng | 园豆:469 (菜鸟二级) | 2015-11-17 11:58
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册