Ejemplo n.º 1
0
        /// <summary>
        /// Registers a cron job.
        /// </summary>
        /// <param name="name">The name of the job.</param>
        /// <param name="jobType">The job's type.</param>
        /// <param name="cron">The cron expression to use.</param>
        /// <param name="retryBehavior">The <see cref="RetryBehavior"/> to use.</param>
        protected void RegisterJob(string name, Type jobType, string cron, RetryBehavior retryBehavior = null)
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                throw new ArgumentException(nameof(cron));
            }
            if (jobType == null)
            {
                throw new ArgumentNullException(nameof(jobType));
            }
            if (cron == null)
            {
                throw new ArgumentNullException(nameof(cron));
            }
            retryBehavior = retryBehavior ?? RetryBehavior.DefaultRetry;

            CrontabSchedule.TryParse(cron);

            if (!typeof(IJob).GetTypeInfo().IsAssignableFrom(jobType))
            {
                throw new ArgumentException(
                          "Cron jobs should extend IJob.", nameof(jobType));
            }

            _entries.Add(new Entry(name, jobType, cron));
        }
Ejemplo n.º 2
0
        static RetryBehavior()
        {
            DefaultRetryCount   = 25;
            DefaultRetryInThunk = retries =>
                                  (int)Math.Round(Math.Pow(retries - 1, 4) + 15 + (_random.Next(30) * (retries)));

            DefaultRetry = new RetryBehavior(true);
            NoRetry      = new RetryBehavior(false);
        }
Ejemplo n.º 3
0
 protected void RegisterJob <T>(string name, string cron, RetryBehavior retryBehavior = null)
     where T : IJob
 {
     RegisterJob(name, typeof(T), cron, retryBehavior);
 }