Esempio n. 1
0
 /// <summary>
 /// 恢复Job
 /// </summary>
 public static bool ResumeJob(JobModel job)
 {
     try
     {
         if (job.Status.ToLower() != "pause")
         {
             Log.NodeLog(job.Id, string.Format("任务“{0}”[{1}]不是【暂停中】的任务,无法恢复!", job.Name, job.Id));
             return(false);
         }
         if (Quartz.ResumeJob(job))
         {
             if (JobService.UpdateState(job.Id, "start"))
             {
                 Log.NodeLog(job.Id, string.Format("任务“{0}”已恢复!", job.Name));
                 return(true);
             }
         }
         else
         {
             Log.NodeLog(job.Id, string.Format("任务“{0}”恢复失败!", job.Name));
         }
         return(false);
     }
     catch (Exception ex)
     {
         Log.NodeLog(GlobalConfig.NodeID, "恢复Job出现异常!", ex);
         return(false);
     }
 }
Esempio n. 2
0
 /// <summary>
 /// 获取当前job数量
 /// </summary>
 public static int GetJobCount()
 {
     try
     {
         return(Quartz.GetCount());
     }
     catch (Exception ex)
     {
         Log.SysLog("节点:" + GlobalConfig.NodeID + " 获取当前job数量失败!", ex);
         return(999);
     }
 }
Esempio n. 3
0
 public static void Init()
 {
     try
     {
         Quartz.InitScheduler();
         Log.SysLog("节点:" + GlobalConfig.NodeID + "初始化任务调度成功!");
     }
     catch (Exception ex)
     {
         Log.SysLog("节点:" + GlobalConfig.NodeID + " 初始化任务调度失败!", ex);
     }
     try
     {
         Quartz.StartScheduler();
         Log.SysLog("节点:" + GlobalConfig.NodeID + " 启动成功!");
     }
     catch (Exception ex)
     {
         Log.SysLog("节点:" + GlobalConfig.NodeID + " 启动失败!", ex);
     }
 }
Esempio n. 4
0
 /// <summary>
 /// 启动Job
 /// </summary>
 public static bool StartJob(JobModel job)
 {
     try
     {
         if (job.Status.ToLower() != "none")
         {
             Log.NodeLog(GlobalConfig.NodeID, ConsoleMsg(job, "不是【未开始】的任务,无法启动!"));
             return(false);
         }
         var taskdir = job.Task.TaskDirName;
         if (Directory.Exists(taskdir))
         {
             if (Quartz.StartJob(job))
             {
                 if (JobService.UpdateState(job.Id, "start"))
                 {
                     Log.NodeLog(GlobalConfig.NodeID, ConsoleMsg(job, "已启动!"));
                     return(true);
                 }
             }
             else
             {
                 Log.NodeLog(GlobalConfig.NodeID, ConsoleMsg(job, "不是正确的Cron表达式,无法启动!"));
             }
         }
         else
         {
             Log.NodeLog(GlobalConfig.NodeID, ConsoleMsg(job, "在插件目录下,无法找到该插件!"));
         }
         return(false);
     }
     catch (Exception ex)
     {
         Log.NodeLog(GlobalConfig.NodeID, string.Format("任务“{0}”[{1}]启动异常!", job.Name, job.Id), ex);
         return(false);
     }
 }
Esempio n. 5
0
 /// <summary>
 /// 删除Job
 /// </summary>
 public static bool DeleteJob(JobModel job)
 {
     try
     {
         if (Quartz.DeleteJob(job))
         {
             if (JobService.Remove(job.Id))
             {
                 Log.NodeLog(job.Id, string.Format("任务“{0}”已删除!", job.Name));
                 return(true);
             }
         }
         else
         {
             Log.NodeLog(job.Id, string.Format("任务“{0}”删除失败!", job.Name));
         }
         return(false);
     }
     catch (Exception ex)
     {
         Log.NodeLog(GlobalConfig.NodeID, "删除Job出现异常!", ex);
         return(false);
     }
 }