示例#1
0
        /// <summary>
        /// /// Generate a random key for the job avoiding collisions with existing keys
        /// </summary>
        /// <param name="quartzFeature">the quartz plugin</param>
        /// <typeparam name="T">the job type</typeparam>
        /// <returns>the job key</returns>
        private static JobKey GetJobIdentity <T>(this QuartzFeature quartzFeature)
        {
            var groupName   = $"{typeof(T).Namespace}";
            var jobName     = $"{typeof(T).Name}";
            var jobIdentity = JobKey.Create($"{jobName}_{NamesGenerator.GetRandomName()}", groupName);

            while (quartzFeature.Jobs.ContainsKey(jobIdentity))
            {
                jobIdentity = JobKey.Create($"{jobName}_{NamesGenerator.GetRandomName()}", groupName);
            }
            return(jobIdentity);
        }
示例#2
0
        /// <summary>
        /// Generate a random key for the trigger avoiding collisions with existing keys
        /// </summary>
        /// <param name="quartzFeature">the quartz plugin</param>
        /// <typeparam name="T">the job type</typeparam>
        /// <returns>the trigger key</returns>
        private static TriggerKey GetTriggerIdentity <T>(this QuartzFeature quartzFeature)
        {
            var groupName       = $"{typeof(T).Namespace}";
            var jobName         = $"{typeof(T).Name}";
            var triggerIdentity = new TriggerKey($"{jobName}_{NamesGenerator.GetRandomName()}", groupName);
            var triggers        = quartzFeature.Jobs.Values.SelectMany(x => x.Triggers.Select(k => k.Key)).ToArray();

            while (triggers.Any(k => k.Equals(triggerIdentity)))
            {
                triggerIdentity = new TriggerKey($"{jobName}_{NamesGenerator.GetRandomName()}", groupName);
            }
            return(triggerIdentity);
        }