Beispiel #1
0
        /// <summary>
        /// Create new job of type <see cref="jobType"/> without any triggers
        /// </summary>
        /// <param name="jobName"></param>
        /// <param name="jobGroup"></param>
        /// <param name="jobType"></param>
        /// <param name="dataMap"><see cref="jobType"/> specific parameters</param>
        /// <param name="description"></param>
        /// <param name="jobId"></param>
        public Guid CreateJob(string jobName, string jobGroup, Type jobType, Dictionary <string, object> dataMap, string description, Guid?jobId = null)
        {
            // Use DefaultGroup if jobGroup is null or empty
            jobGroup = (!string.IsNullOrEmpty(jobGroup)) ? jobGroup : JobKey.DefaultGroup;

            var        jobbuilder = JobBuilder.Create(jobType);
            IJobDetail jobDetail  = jobbuilder.WithDescription(description)
                                    .WithIdentity(jobName, jobGroup).StoreDurably(true).RequestRecovery(false)
                                    .Build();

            foreach (var mapItem in dataMap)
            {
                jobDetail.JobDataMap.Add(mapItem.Key, mapItem.Value);
            }

            Guid id;

            using (var tran = new TransactionScope())
            {
                id = _persistanceStore.UpsertJobKeyIdMap(jobName, jobGroup, jobId);
                _scheduler.AddJob(jobDetail, true);
                tran.Complete();
            }

            return(id);
        }