我心中的核心组件(可插拔的AOP)~调度组件quartz.net续~任务管理器的开发

回到目录

对于任务调度来说,越来越多的团队选择了quartz,它在java和.net环境下表现都十分优秀,配置简单,功能强大,时间表达式配置灵活,但在使用时,还是感觉缺点什么,怎么说,你在服务器上安装了一个任务,然后然它们去运行,我们在客户端或者一个web网站里,如果对服务端的任务进行管理呢,这是一个大难题,而今天我要写的就是如何去实现这样一个任务管理器!

小知识

quartz为我们提供了远程模式,即可以监听一个端口,用来等待客户端去调用,呵呵

CrystalQuartz用来创建远程链接对象

  private static RemoteSchedulerProvider remoteSchedulerProvider = new CrystalQuartz.Core.SchedulerProviders.RemoteSchedulerProvider();
remoteSchedulerProvider.SchedulerHost = System.Configuration.ConfigurationManager.AppSettings["SchedulerHost"];

效果预览

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAA2oAAACDCAIAAABz6n+LAAAOAElEQVR4nO3du5HjuBYA0M6JeYylJMaXMXnInQjak7VxqJ77amojeCn0M7pFkcSHF6J+PTintrYkCgB/F+AlKPW8fZz9+oY+AAB4rLfx1a9fv/7z33+/0X/SRwCAx5M+AgDQQPoIAEAD6SMAAA2kjwAANJA+AgDQIJQ+vr291ReOr7ML6+1cUUb6CADwLCvp49vcdEma873lVFLDbIF6C9JHAIDnan54XZmJTOcgSzOU2bxw0cjqTKT0EQDg8dZnHyvpXXb2MX1bmnqsZKj1eUfpIwDAs6zPPqYzi9P0LvugOfsikj6mGaeH1wAAL6WWPma/hpidg8ymkpEq2Uyx8pH0EQDguZp/eR3JBeuzmNkUs7U16SMAwFNc88vrSvpYyQtXM85sZllJJaWPAACPd+PZx7RkPH1sKiZ9BAB4itAvr0v/X0wcbpx9lD4CALy+lZ/ORF6UZhyvSB+zT7SljwAAryP0h3vSGcfK3OHq7GOpTGlGU/oIAPA6mv/Vmdf5T/oIAPB40kcAABpIHwEAaCB9BACggfQRAIAG0kcAABrM0sdv54kHDgCgT2/rRQAA4Ez6CABAA+kjAAANpI8AADSQPgIA0ED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Vg5JIwSmP38dYPrxNwL8WYFP9uC35HxTjsG8JDBVb7fg+cBUjSPLOT6ZovYMTKt7tw1LNnWHUFJoZDCd+Jbcs/yhQpbUA0S8KTB92ArTNnBEAso+KyXB9hTm/h0CUzmlbQNK4U17U2AqvBUCEx9OPUBEYaQ88EcpWwtJSy88JZdLA5EZ9x0T/yqRbG9vG1BOJG8KJbl0skqZ1Ua+KTBtX+5QIzDxCdQDRIwzUvzPd7Vtz7YJTHRDPUDEOCNFYNK2PdsmMNEN9QAR44wUgUnb9mybwEQ31ANEjDNSBCZt27NtAhPdUA8QMc5IEZi0bc+2CUx0Qz1AxDgjRWDStj3bJjDRDfUAEeOMlLsC027u7YW29dI2gYluqAeIGGekjNNTWiAw0Q31ABHjjJRxekoLDl8AABQd/gcAQJHABABQITABAFT8H5Wknf2pEM7jAAAAAElFTkSuQmCC" alt="" />

说做就做

        /// <summary>
/// 恢复开始任务
/// </summary>
/// <param name="jobName"></param>
/// <param name="group"></param>
/// <returns></returns>
public ActionResult Start(string jobName, string group)
{
remoteSchedulerProvider.Scheduler.ResumeJob(new JobKey(jobName, group));
return RedirectToAction("Index");
}
/// <summary>
/// 暂停任务
/// </summary>
/// <param name="jobName"></param>
/// <param name="group"></param>
/// <returns></returns>
public ActionResult Stop(string jobName, string group)
{
remoteSchedulerProvider.Scheduler.PauseJob(new JobKey(jobName, group));
return RedirectToAction("Index");
}

上面代码可以实现界面中的“开始”和暂停“两个功能,主要是对trigger进行控制的,值得注意的是,如果你修改的时间表达式,需要从新启动服务才会生效!

回到目录

上一篇:我心中的核心组件(可插拔的AOP)~第十三回 实现AOP的拦截组件Unity.Interception


下一篇:什么是DOM,DOM level 1\2\3 的区别是什么