public bool AddHttpJob(JobParamHttpModel job)
        {
            try
            {
                JobKey jobKey = CreateJobKey(job.JobName, job.JobGroupName);
                var    bl     = _scheduler.CheckExists(jobKey).GetAwaiter().GetResult();
                if (!bl)
                {
                    var jobbuilder = JobBuilder.Create <HttpJob>()
                                     .WithIdentity(jobKey)
                                     .UsingJobData(JobConfig.CallbackUrl, job.CallbackUrl);

                    var param = JobUtils.GetDictToString(job.CallbackParams);
                    if (!string.IsNullOrEmpty(param))
                    {
                        jobbuilder.UsingJobData(JobConfig.CallbackParams, JobUtils.GetDictToString(job.CallbackParams));
                    }

                    var jobDetail = jobbuilder.Build();

                    ITrigger trigger = CreateTrigger(job, jobKey);

                    _scheduler.ScheduleJob(jobDetail, trigger).GetAwaiter().GetResult();
                    return(true);
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex);
            }
            return(false);
        }
Example #2
0
        public bool RunAtOnce(string jobName, string jobGroupName)
        {
            try
            {
                JobKey jobKey = CreateJobKey(jobName, jobGroupName);

                JobDataModel jobData = Xml.XmlJobManage.GetJobDataByKey(jobKey);
                if (jobData == null)
                {
                    return(false);
                }

                JobKey jobKeyOnce = CreateJobKey(jobName, JobConfig.JobGroupNameOnce);

                var type = typeof(HttpJob);

                if (jobData.JobType == JobType.Assembly)
                {
                    string   path     = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, jobData.AssemblyDllName);
                    Assembly assembly = Assembly.LoadFile(path);
                    type = assembly.GetType(jobData.TypeFullName);
                }

                var bl = _scheduler.CheckExists(jobKeyOnce).GetAwaiter().GetResult();
                if (bl)
                {
                    _scheduler.DeleteJob(jobKeyOnce);
                }
                IJobDetail jobDetail = JobBuilder.Create(type)
                                       .WithIdentity(jobKeyOnce)
                                       .UsingJobData(JobConfig.CallbackUrl, jobData.CallbackUrl)
                                       .UsingJobData(JobConfig.CallbackParams, JobUtils.GetDictToString(jobData.CallbackParams))
                                       .Build();

                DateTimeOffset startTime = DateBuilder.NextGivenSecondDate(null, 2);
                ITrigger       trigger   = TriggerBuilder.Create()
                                           .WithIdentity(JobConfig.GetTriggerNameOnce(jobName), JobConfig.TriggerGroupNameOnce)
                                           .StartAt(startTime)
                                           .Build();

                _scheduler.ScheduleJob(jobDetail, trigger).GetAwaiter().GetResult();
                return(true);
            }
            catch (Exception ex)
            {
                logger.Error(ex);
            }

            return(false);
        }
        /// <summary>
        /// 参数是否相同
        /// </summary>
        /// <returns></returns>
        protected bool IsSameParam(JobParamHttpModel job, JobDataModel data)
        {
            string map = JobUtils.GetDictToString(data.CallbackParams);

            string newParam = JobUtils.GetDictToString(job.CallbackParams);

            if (data.CallbackUrl != job.CallbackUrl)
            {
                return(false);
            }

            if (map.ToString() != newParam)
            {
                return(false);
            }

            return(true);
        }