Browse Source

定时任务端口多进程处理

zhoufan 3 years ago
parent
commit
b44c610e76

+ 19 - 12
CallCenterApi/CallCenterApi.Interface/CallCenterApi.Interface/Global.asax.cs

@@ -1,15 +1,12 @@
1 1
 using CallCenter.QuartzService;
2 2
 using CallCenter.Utility;
3 3
 using CallCenterApi.Common;
4
-using CallCenterApi.Interface.Models.Common;
5 4
 using System;
6 5
 using System.Collections.Generic;
7
-using System.Linq;
6
+using System.Threading.Tasks;
8 7
 using System.Web;
9 8
 using System.Web.Mvc;
10 9
 using System.Web.Routing;
11
-using System.Web.Script.Serialization;
12
-using System.Web.Security;
13 10
 
14 11
 namespace CallCenterApi.Interface
15 12
 {
@@ -22,15 +19,25 @@ namespace CallCenterApi.Interface
22 19
             RouteConfig.RegisterRoutes(RouteTable.Routes);
23 20
             //clq 增加异常日志记录 自定义 HandleErrorAttribute
24 21
             FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
25
-            if (!CommonHelper.PortInUse(Int32.Parse(Configs.GetValue("quartz_port"))))
22
+
23
+            int port = Int32.Parse(Configs.GetValue("quartz_port"));
24
+            Task.Run(() =>
26 25
             {
27
-                _worker = new QuartzWorker();
28
-                _worker.AddWork(new SatisfactionClose());
29
-                _worker.AddWork(new ZhengWuDuiJie());
30
-                _worker.AddWork(new Peoplewebsite());
31
-                //_worker.AddWork(new PushWorkorder());
32
-                _worker.Start();
33
-            }
26
+                Task.Delay(TimeSpan.FromMinutes(1)).Wait();
27
+                if (!CommonHelper.PortInUse(port))
28
+                {
29
+                    _worker = new QuartzWorker(port);
30
+                    _worker.AddWork(new SatisfactionClose());
31
+                    _worker.AddWork(new ZhengWuDuiJie());
32
+                    _worker.AddWork(new Peoplewebsite());
33
+                    //_worker.AddWork(new PushWorkorder());
34
+                    _worker.Start();
35
+                }
36
+
37
+            }).ContinueWith(p =>
38
+            {
39
+                System.Diagnostics.Debug.WriteLine(DateTime.Now);
40
+            });
34 41
         }
35 42
         protected void Application_End()
36 43
         {

+ 2 - 2
CallCenterCommon/CallCenter.QuartzService/QuartzWorker.cs

@@ -9,7 +9,7 @@ namespace CallCenter.QuartzService
9 9
     public class QuartzWorker
10 10
     {
11 11
         readonly IScheduler _scheduler;
12
-        public QuartzWorker()
12
+        public QuartzWorker(int port)
13 13
         {
14 14
             var properties = new NameValueCollection();
15 15
             //properties["quartz.scheduler.instanceName"] = "RemoteServerSchedulerClient";
@@ -20,7 +20,7 @@ namespace CallCenter.QuartzService
20 20
 
21 21
             // 远程输出配置
22 22
             properties["quartz.scheduler.exporter.type"] = "Quartz.Simpl.RemotingSchedulerExporter, Quartz";
23
-            properties["quartz.scheduler.exporter.port"] = Configs.GetValue("quartz_port");
23
+            properties["quartz.scheduler.exporter.port"] = port.ToString();
24 24
             properties["quartz.scheduler.exporter.bindName"] = "QuartzScheduler";
25 25
             properties["quartz.scheduler.exporter.channelType"] = "tcp";
26 26