当前位置: 首页 > news >正文

东昌府做网站推广夺宝网站开发

东昌府做网站推广,夺宝网站开发,建网站手机版,上传到网站根目录这篇文章我们来了解一些项目中的一个很重要的功能#xff1a;任务调度 可能有些同学还不了解这个#xff0c;其实简单点说任务调度与数据库中的Job是很相似的东西 只不过是运行的物理位置与管理方式有点不一样#xff0c;从功能上来说我觉得还是差不多的#xff0c; 存储过…这篇文章我们来了解一些项目中的一个很重要的功能任务调度 可能有些同学还不了解这个其实简单点说任务调度与数据库中的Job是很相似的东西 只不过是运行的物理位置与管理方式有点不一样从功能上来说我觉得还是差不多的 存储过程有很大的局限性耦合性也太高所以最好把系统的一些Job放在代码层 于是就有了Quartz.net我们本篇就是针对Quartz.net的二次开发   一、新建HelloJob HelloJob.cs示例Job每次执行都输出msg变量中的信息 1 using Common.Logging;2 using Quartz; 3 4 namespace Job.Items 5 { 6 public class HelloJob : IJob 7 { 8 public const string Message msg; 9 private static readonly ILog log LogManager.GetLogger(typeof(HelloJob)); 10 11 public virtual void Execute(IJobExecutionContext context) 12 { 13 var jobKey context.JobDetail.Key; 14 var message context.JobDetail.JobDataMap.GetString(Message); 15 log.InfoFormat(HelloJob: msg: {0}, message); 16 } 17 } 18 } HelloJobExample.cs每5秒执行一次 1 public class HelloJobExample 2 { 3 public virtual void Run() 4 { 5 ISchedulerFactory sf new StdSchedulerFactory(); 6 IScheduler sched sf.GetScheduler(); 7 8 IJobDetail job JobBuilder.CreateHelloJob() 9 .WithIdentity(job1, group1) 10 .Build(); 11 12 JobDataMap map job.JobDataMap; 13 map.Put(msg, Your remotely added job has executed!); 14 15 ITrigger trigger TriggerBuilder.Create() 16 .WithIdentity(trigger1, group1) 17 .ForJob(job.Key) 18 .WithCronSchedule(/5 * * ? * *) 19 .Build(); 20 21 sched.ScheduleJob(job, trigger); 22 sched.Start(); 23 } 24 } 好了有效代码就那么多我们来试试 1 class Program2 {3 static void Main(string[] args) 4 { 5 var example new HelloJobExample(); 6 example.Run(); 7 8 Console.ReadKey(); 9 } 10 } 貌似没什么问题如愿地执行了。   但是我们想想实际运行中执行任务的服务器一般都是独立出来的那怎么去管理这些任务的开启、关闭及暂停呢 肯定不能每次手动去操作那太麻烦了。我们的希望是在应用中系统管理后台去管理这些任务。万幸Quartz.net足够强大 他是支持远程操作的没有太深入了解不过看调用参数应该是通过TCP请求进行操作的我们试试看   二、Job远程管理 2.1、新建Job.Items项目把之前新建的HelloJob.cs放在其中 2.2、新建Job.Server项目 新建RemoteServer.cs 1 public class RemoteServer : ILjrJob2 { 3 public string Name 4 { 5 get { return GetType().Name; } 6 } 7 8 public virtual void Run() 9 { 10 ILog log LogManager.GetLogger(typeof(RemoteServer)); 11 12 NameValueCollection properties new NameValueCollection(); 13 properties[quartz.scheduler.instanceName] RemoteServer; 14 properties[quartz.threadPool.type] Quartz.Simpl.SimpleThreadPool, Quartz; 15 properties[quartz.threadPool.threadCount] 5; 16 properties[quartz.threadPool.threadPriority] Normal; 17 properties[quartz.scheduler.exporter.type] Quartz.Simpl.RemotingSchedulerExporter, Quartz; 18 properties[quartz.scheduler.exporter.port] 555; 19 properties[quartz.scheduler.exporter.bindName] QuartzScheduler; 20 properties[quartz.scheduler.exporter.channelType] tcp; 21 properties[quartz.scheduler.exporter.channelName] httpQuartz; 22 properties[quartz.scheduler.exporter.rejectRemoteRequests] true; 23 24 } 25 } 2.3、新建控制器HelloJobController 1 public class HelloJobController : Controller2 { 3 public ActionResult Index() 4 { 5 try 6 { 7 if (HelloJobHelper.Trigger ! null) 8 { 9 ViewBag.JobKey remotelyAddedJob; 10 ViewBag.State HelloJobHelper.Scheduler.GetTriggerState(HelloJobHelper.Trigger.Key); 11 ViewBag.StartTime HelloJobHelper.Trigger.StartTimeUtc.ToString(); 12 } 13 else 14 { 15 ViewBag.State 获取Job执行状态失败; 16 } 17 } 18 catch (Exception ex) 19 { 20 ViewBag.State Job服务器连接失败; 21 } 22 23 return View(); 24 } 25 public ActionResult Run() 26 { 27 HelloJobHelper.RunJob(); 28 29 return RedirectToAction(Index, HelloJob); 30 } 31 public ActionResult Pause() 32 { 33 HelloJobHelper.PauseJob(); 34 35 return RedirectToAction(Index, HelloJob); 36 } 37 public ActionResult Resume() 38 { 39 HelloJobHelper.ResumeJob(); 40 return RedirectToAction(Index, HelloJob); 41 } 42 } 2.4、新建HelloJobHelper 先配置连接远端任务服务器的参数这个要和上面的RemoteServer.cs对应 1 properties[quartz.scheduler.proxy] true; 2 properties[quartz.scheduler.proxy.address] tcp://127.0.0.1:555/QuartzScheduler; 我们来看看开始操作运行这个方法任务服务器将自动开启这个Job 1 public static void RunJob()2 { 3 if (!scheduler.CheckExists(jobKey)) 4 { 5 IJobDetail job JobBuilder.CreateHelloJob() 6 .WithIdentity(jobKey) 7 .Build(); 8 9 JobDataMap map job.JobDataMap; 10 map.Put(msg, Your remotely added job has executed!); 11 12 ITrigger trigger TriggerBuilder.Create() 13 .WithIdentity(triggerKey) 14 .ForJob(job.Key) 15 .WithCronSchedule(/5 * * ? * *) 16 .Build(); 17 18 scheduler.ScheduleJob(job, trigger); 19 20 JobDetail job; 21 Trigger trigger; 22 } 23 } 暂停比较简单 1 public static void PauseJob() 2 { 3 scheduler.PauseJob(jobKey); 4 } 2.5、View 1 {2 ViewBag.Title Index;3 Layout ~/Views/Shared/_Bootstrap.cshtml; 4 } 5 6 !DOCTYPE html 7 8 html 9 head 10 meta nameviewport contentwidthdevice-width / 11 titleIndex/title 12 style 13 .col-sm-offset-2 { 14 margin-left:20px; 15 } 16 /style 17 /head 18 body 19 br / 20 using (Html.BeginForm(Run, HelloJob, null, FormMethod.Post, new { id form1, class form-horizontal, role form })) 21 { 22 Html.AntiForgeryToken() 23 div classform-group 24 div classcol-sm-offset-2 col-sm-10 25 input typehidden nameId idId / 26 button typesubmit classbtn btn-defaultRun/button 27 /div 28 /div 29 } 30 31 using (Html.BeginForm(Pause, HelloJob, null, FormMethod.Post, new { id form2, class form-horizontal, role form })) 32 { 33 Html.AntiForgeryToken() 34 div classform-group 35 div classcol-sm-offset-2 col-sm-10 36 input typehidden nameId idId / 37 button typesubmit classbtn btn-defaultPause/button 38 /div 39 /div 40 } 41 42 using (Html.BeginForm(Resume, HelloJob, null, FormMethod.Post, new { id form3, class form-horizontal, role form })) 43 { 44 Html.AntiForgeryToken() 45 div classform-group 46 div classcol-sm-offset-2 col-sm-10 47 input typehidden nameId idId / 48 button typesubmit classbtn btn-defaultResume/button 49 /div 50 /div 51 } 52 53 br / 54 div 55 ul 56 liViewBag.JobKey: ViewBag.JobKey/li 57 liViewBag.State: ViewBag.State/li 58 转载于:https://www.cnblogs.com/MuNet/p/6688064.html
http://www.sadfv.cn/news/126415/

相关文章:

  • 仿5173网站wordpress相关的网站
  • 地铁建设网站装修案例视频
  • 顺义区网站建设知名的网页制作公司哪家好
  • 基层建设期刊在哪个网站上检索好的建筑设计网站推荐
  • 宁夏找人做网站多少钱广告网站留电话整人
  • 湖北省建设厅官方网站电话成品人和精品人的区别在哪
  • 推广做网站联系方式关于网站建设电话销售的话术
  • 网站建设网页如何做好外贸网站建设
  • 做电商网站前端的技术选型是广安做网站
  • 网站建设培训中心青岛手机端网络推广培训
  • 郑州网站搭建扁平化网站设计方案
  • 制作网站用什么软件好手机网站的必要性
  • 漂亮的数据型网站宁波建网站推荐
  • 莱芜住房和城乡建设部网站网站被采集
  • 仿制型模板网站服装定制流程
  • 微小店适合卖做分类网站吗公司公众网站微信平台建设方案
  • asp.net 网站管理工具 安全深圳物流公司查询大全
  • 58同城网站建设思路免费自助网站
  • 溧阳建设局网站6江苏盐城网络科技有限公司
  • 深圳专门网站建设金华网站建设外包
  • 网上网站代码可以下载吗万维网网站注册
  • 珠海网站制作品牌策划网站推广教学
  • 正在建设的网站可以随时进入吗织梦网站自适应怎么做
  • 住房公积金网站怎么做减员建筑人才网官方网站中国建筑科学院有限公司认证中心
  • 江门企业做网站解决wordpress慢
  • 基于开源框架的网站开发如何 建设一个网站
  • 可以做家装设计的网站河北省建设工程安全生产监督管理网站
  • 自己做视频直播网站有哪些网站可以做微商
  • 工信部 网站备案江西建设质量安全监督网站
  • 顺企网网站建设北京网站推广排名外包