Ejemplo n.º 1
0
        private void CheckExistingTimeouts()
        {
            DateTime now = SystemUtil.UtcNow;

            _log.DebugFormat("TimeoutService Checking For Existing Timeouts: {0}", now.ToLocalTime());

            try
            {
                var sagas = _repository.Where(x => x.TimeoutAt < now && x.CurrentState == TimeoutSaga.WaitingForTime).ToArray();
                foreach (TimeoutSaga saga in sagas)
                {
                    TimeoutSaga instance = saga;

                    _fiber.Add(() => PublishTimeoutExpired(instance.TimeoutId, instance.Tag));
                }
            }
            catch (Exception ex)
            {
                _log.Error("Error rescheduling existing timeouts", ex);
            }
            finally
            {
                if (_unschedule != null)
                {
                    _unschedule.Cancel();
                }

                _log.DebugFormat("Scheduling next check at " + DateTime.Now);
                _unschedule = _scheduler.Schedule(1000, _fiber, CheckExistingTimeouts);
            }
        }
Ejemplo n.º 2
0
        public void Stop()
        {
            if (_scheduled != null)
            {
                _scheduled.Cancel();
                _scheduled = null;
            }

            if (_scheduler != null)
            {
                _scheduler.Stop(60.Seconds());
                _scheduler = null;
            }

            if (_fiber != null)
            {
                _fiber.Shutdown(60.Seconds());
            }

            if (_unsubscribeAction != null)
            {
                _unsubscribeAction();
                _unsubscribeAction = null;
            }
        }
Ejemplo n.º 3
0
 void CancelTimeout()
 {
     if (_scheduledAction != null)
     {
         _scheduledAction.Cancel();
     }
 }
Ejemplo n.º 4
0
        public void Should_run_the_action_until_disabled()
        {
            Fiber     fiber     = new PoolFiber();
            Scheduler scheduler = new TimerScheduler(new PoolFiber());

            Stopwatch elapsed = Stopwatch.StartNew();

            int count  = 0;
            var called = new Future <int>();
            var failed = new Future <bool>();

            ScheduledOperation scheduledAction = null;

            scheduledAction = scheduler.Schedule(TimeSpan.Zero, 100.Milliseconds(), fiber, () =>
            {
                count++;
                if (count == 10)
                {
                    called.Complete(count);
                    scheduledAction.Cancel();
                }
                else if (count > 10)
                {
                    failed.Complete(true);
                }
            });

            called.WaitUntilCompleted(5.Seconds()).ShouldBeTrue();

            elapsed.Stop();

            failed.WaitUntilCompleted(200.Milliseconds()).ShouldBeFalse();

            Trace.WriteLine("Time Period: " + elapsed.ElapsedMilliseconds);
        }
Ejemplo n.º 5
0
        public void Stop()
        {
            _scheduled.Cancel();
            _scheduled = null;

            lock (_workers)
                _workers.Clear();

            _unsubscribeAction();
        }
Ejemplo n.º 6
0
        void Dispose(bool disposing)
        {
            if (_disposed)
            {
                return;
            }
            if (disposing)
            {
                _scheduledAction.Cancel();
                _scheduledAction = null;
            }

            _disposed = true;
        }
Ejemplo n.º 7
0
        void Dispose(bool disposing)
        {
            if (_disposed)
            {
                return;
            }
            if (disposing)
            {
                _scheduledAction.Cancel();
                _connection.Dispose();
                _fileSystemEventProducer.Dispose();
            }

            _disposed = true;
        }
Ejemplo n.º 8
0
 public void Stop()
 {
     _bus.ControlBus.Publish(new EndpointWentOffline(SystemId, _controlUri, _dataUri, _heartbeatIntervalInSeconds));
     _unschedule.Cancel();
     _unsubscribe();
 }