Esempio n. 1
0
 public bool Remove(Guid jobId)
 {
     lock (syncLock)
     {
         if (JobRuntimePool.ContainsKey(jobId))
         {
             JobRuntimeInfo jobRuntimeInfo = null;
             JobRuntimePool.TryGetValue(jobId, out jobRuntimeInfo);
             if (jobRuntimeInfo != null)
             {
                 var tiggerKey = new TriggerKey(jobRuntimeInfo.JobModel.JobName,
                                                jobRuntimeInfo.JobModel.JobGroup);
                 scheduler.PauseTrigger(tiggerKey);
                 scheduler.UnscheduleJob(tiggerKey);
                 scheduler.DeleteJob(new JobKey(jobRuntimeInfo.JobModel.JobName,
                                                jobRuntimeInfo.JobModel.JobGroup));
                 JobRuntimePool.TryRemove(jobId, out jobRuntimeInfo);
                 JobOperator.UpdateJobStatus(jobRuntimeInfo.JobModel.ID, 0);
                 if (!JobRuntimePool.Any(p => p.Value.AppDomain == jobRuntimeInfo.AppDomain))
                 {
                     AppDomainLoader <BaseJob> .UnLoad(jobRuntimeInfo.AppDomain);
                 }
                 return(true);
             }
         }
         return(false);
     }
 }
Esempio n. 2
0
        public bool Add(Guid jobId, JobRuntimeInfo jobRuntimeInfo)
        {
            lock (syncLock)
            {
                if (!JobRuntimePool.ContainsKey(jobId))
                {
                    var jobInfo  = jobRuntimeInfo.JobModel;
                    var jobName  = jobInfo.JobName;
                    var jobGroup = string.IsNullOrWhiteSpace(jobInfo.JobGroup) ? null : jobInfo.JobGroup;
                    var jobKey   = new JobKey(jobName, jobGroup);
                    if (JobRuntimePool.TryAdd(jobId, jobRuntimeInfo))
                    {
                        //Set job status to stop
                        if (JobOperator.UpdateJobStatus(jobInfo.ID, 0))
                        {
                            jobInfo.Status = 0;
                        }

                        IDictionary <string, object> jobData = new Dictionary <string, object>()
                        {
                            ["JobId"] = jobInfo.ID.ToString()
                        };

                        //Builds the job detail
                        var jobDetail = JobBuilder.Create <QuartzJob>()
                                        .WithIdentity(jobKey)
                                        .SetJobData(new JobDataMap(jobData))
                                        .Build();

                        //Builds the job trigger
                        var jobTriggerBuilder = TriggerBuilder.Create()
                                                .WithIdentity($"{jobName}Trigger", jobGroup)
                                                .WithDescription($"{jobName} Trigger")
                                                .WithCronSchedule(jobInfo.CronExpression, x => x.WithMisfireHandlingInstructionDoNothing());
                        //if (jobInfo.StartTime.HasValue)
                        //    jobTriggerBuilder.StartAt(jobInfo.StartTime.Value);
                        //if (jobInfo.EndTime.HasValue)
                        //    jobTriggerBuilder.EndAt(jobInfo.EndTime.Value);
                        var jobTrigger = jobTriggerBuilder.Build();

                        //Decides whether to schedule the job by status
                        scheduler.ScheduleJob(jobDetail, jobTrigger);
                        //if (jobInfo.Status == 0) scheduler.PauseJob(jobKey);
                        return(true);
                    }
                }
                return(false);
            }
        }
Esempio n. 3
0
 public JobRuntimeInfo Get(Guid jobId)
 {
     if (!JobRuntimePool.ContainsKey(jobId))
     {
         return(null);
     }
     lock (syncLock)
     {
         if (JobRuntimePool.ContainsKey(jobId))
         {
             JobRuntimeInfo jobRuntimeInfo = null;
             JobRuntimePool.TryGetValue(jobId, out jobRuntimeInfo);
             return(jobRuntimeInfo);
         }
         return(null);
     }
 }