Exemple #1
0
        public void Schedule(ISchedulingContext context)
        {
            Ensure.NotNull(context, "context");

            DateTime executeAt;

            if (context.Envelope.TryGetExecuteAt(out executeAt))
            {
                TimeSpan delay = dateTimeProvider.GetExecutionDelay(executeAt);
                if (delay > longRunnerThreshold)
                {
                    log.Info(context.Envelope, "Got envelope for long runner with current delay '{0}'.", delay);
                    ScheduleLongRunner(context);
                }
                else if (delay > TimeSpan.Zero)
                {
                    log.Info(context.Envelope, "Creating timer with current delay '{0}'.", delay);
                    Timer timer = new Timer(
                        OnScheduled,
                        context,
                        delay,
                        TimeSpan.FromMilliseconds(-1)
                        );

                    lock (timersLock)
                        timers.Add(new Tuple <Timer, ISchedulingContext>(timer, context));

                    log.Debug(context.Envelope, "Timer registered.");
                }
                else
                {
                    // This should be handled by the calling infrastructure.
                    log.Info(context.Envelope, "Got envelope with current delay in past '{0}'. Executing.", delay);
                    context.Execute();
                }
            }
            else
            {
                // This should be handled by the calling infrastructure.
                log.Info(context.Envelope, "Got envelope without 'ExecuteAt' metadata. Executing.");
                context.Execute();
            }
        }
Exemple #2
0
        /// <summary>
        /// When the context should be executed and removed from the <see cref="timers"/>.
        /// </summary>
        /// <param name="state">The context to be executed.</param>
        private void OnScheduled(object state)
        {
            ISchedulingContext context = (ISchedulingContext)state;

            log.Debug(context.Envelope, "Envelope timer callback raised.");

            Remove(context);

            log.Info(context.Envelope, "Executing.");

            context.Execute();

            log.Debug(context.Envelope, "Envelope timer callback ended.");
        }
Exemple #3
0
        public void Schedule(ISchedulingContext context)
        {
            Ensure.NotNull(context, "context");

            DateTime executeAt;

            if (context.Envelope.TryGetExecuteAt(out executeAt))
            {
                TimeSpan delay = dateTimeProvider.GetExecutionDelay(executeAt);
                if (delay > longRunnerThreshold)
                {
                    ScheduleLongRunner(context);
                }
                else if (delay > TimeSpan.Zero)
                {
                    Timer timer = new Timer(
                        OnScheduled,
                        context,
                        delay,
                        TimeSpan.FromMilliseconds(-1)
                        );

                    lock (timersLock)
                        timers.Add(new Tuple <Timer, ISchedulingContext>(timer, context));
                }
                else
                {
                    // This should be handled by the calling infrastructure.
                    context.Execute();
                }
            }
            else
            {
                // This should be handled by the calling infrastructure.
                context.Execute();
            }
        }
Exemple #4
0
        /// <summary>
        /// When the context should be executed and removed from the <see cref="timers"/>.
        /// </summary>
        /// <param name="state">The context to be executed.</param>
        private void OnScheduled(object state)
        {
            ISchedulingContext context = (ISchedulingContext)state;

            lock (timersLock)
            {
                Tuple <Timer, ISchedulingContext> item = timers.FirstOrDefault(t => t.Item2 == context);
                if (item != null)
                {
                    timers.Remove(item);
                }
            }

            context.Execute();
        }
Exemple #5
0
 public void Execute()
 {
     collection.Remove(inner);
     inner.Execute();
 }