示例#1
0
 public JobDto Create(JobDto dto)
 {
     using (var ctx = new BatchJobDbContext())
     {
         var jobGroup = ctx.JobGroups.Find(dto.GroupId);
         var isExists = jobGroup.Jobs.Any(a => a.Name == dto.Name);
         if (isExists)
         {
             throw new BusinessException("当前工作组下存在重名作业.");
         }
         var entity = Mapper.Map <JobEntity>(dto);
         entity.JobGroup = jobGroup;
         entity          = ctx.Jobs.Add(entity);
         ctx.SaveChanges();
         dto = Mapper.Map <JobDto>(entity);
         return(dto);
     }
 }
示例#2
0
 public bool TryRemoveService(int serviceId, out int?jobId)
 {
     using (var ctx = new BatchJobDbContext())
     {
         var entity = ctx.Services.Find(serviceId);
         if (entity != null)
         {
             jobId = entity.Job.Id;
             if (entity.ServiceParameters != null)
             {
                 entity.ServiceParameters.Clear();
             }
             ctx.Services.Remove(entity);
             ctx.SaveChanges();
             return(true);
         }
         jobId = null;
         return(false);
     }
 }
示例#3
0
 public void StopJob(int jobId)
 {
     using (var ctx = new BatchJobDbContext())
     {
         try
         {
             var job = ctx.Jobs.Find(jobId);
             if (job != null)
             {
                 var scheduler = QuartzHelper.GetScheduler(job.JobGroup.Scheduler.Name, job.JobGroup.Scheduler.ThreadPoolSize, (int)job.JobGroup.Scheduler.Priority);
                 scheduler.PauseJob(job.Code, job.JobGroup.Name);
                 job.StopJob();
                 ctx.SaveChanges();
             }
         }
         catch (Exception ex)
         {
             throw ex;
         }
     }
 }