示例#1
0
 public ActionResult RunJob(string serviceName, string jobName)
 {
     try {
         var info = QuartzHelper.GetServiceInfo(serviceName, true);
         if (info == null)
         {
             return(Json(new { code = 0, date = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), msg = $"服务【{serviceName}】不存在!" }, JsonRequestBehavior.AllowGet));
         }
         var r = QuartzHelper.GetJob(info.Path, jobName);
         if (r == 0)
         {
             return(Json(new { code = 0, date = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), msg = $"任务【{jobName}】不存在!" }, JsonRequestBehavior.AllowGet));
         }
         if (r == 2 && info.IsRun)
         {
             return(Json(new { code = 0, date = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), msg = $"任务【{jobName}】将被执行或正在执行!" }, JsonRequestBehavior.AllowGet));
         }
         Process.Start(info.Path, jobName);
         return(Json(new { code = 1, date = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), msg = $"任务【{jobName}】开始执行!" }, JsonRequestBehavior.AllowGet));
     } catch (Exception ex) {
         return(Json(new { code = 0, date = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), msg = $"任务【{jobName}】执行出错:" + ex.Message }, JsonRequestBehavior.AllowGet));
     }
 }