Пример #1
0
        /// <inheritdoc />
        public IHeartBeatStatus Send(IMessageContext context)
        {
            var spanContext = context.Extract(_tracer, _headers);

            if (spanContext != null)
            {
                using (IScope scope = _tracer.BuildSpan("SendHeartBeat").AddReference(References.FollowsFrom, spanContext).StartActive(finishSpanOnDispose: true))
                {
                    var status = _handler.Send(context);
                    if (status.LastHeartBeatTime.HasValue)
                    {
                        scope.Span.SetTag("HeartBeatValue", status.LastHeartBeatTime.Value.ToString(System.Globalization.CultureInfo.InvariantCulture));
                    }
                    return(status);
                }
            }
            else
            {
                using (IScope scope = _tracer.BuildSpan("SendHeartBeat").StartActive(finishSpanOnDispose: true))
                {
                    scope.Span.AddMessageIdTag(context);
                    var status = _handler.Send(context);
                    if (status.LastHeartBeatTime.HasValue)
                    {
                        scope.Span.SetTag("HeartBeatValue", status.LastHeartBeatTime.Value.ToString(System.Globalization.CultureInfo.InvariantCulture));
                    }
                    return(status);
                }
            }
        }
 /// <summary>
 /// Updates the heart beat for a record.
 /// </summary>
 /// <param name="context">The context.</param>
 /// <returns></returns>
 public IHeartBeatStatus Send(IMessageContext context)
 {
     using (_timer.NewContext())
     {
         return(_handler.Send(context));
     }
 }
Пример #3
0
        /// <inheritdoc />
        public IHeartBeatStatus Send(IMessageContext context)
        {
            IHeartBeatStatus result = null;

            if (_policy == null)
            {
                _policies.Registry.TryGet(_policies.Definition.SendHeartBeat, out _policy);
            }

            if (_policy != null)
            {
                _policy.Execute(() => result = _handler.Send(context));
            }
            else //no policy found
            {
                result = _handler.Send(context);
            }
            return(result);
        }
Пример #4
0
        public HeartBeat(ISendHeartBeat sendHeartBeat)
        {
            m_sendHeartBeat = sendHeartBeat;

            // Create a timer with a two second interval.
            m_timer = new Timer(GlobalDefine.HeartBeatInterval);
            // Hook up the Elapsed event for the timer.
            m_timer.Elapsed  += OnTimedEvent;
            m_timer.AutoReset = true;
            m_timer.Enabled   = true;
            m_sendHeartBeat.Send();
        }
        /// <inheritdoc />
        public IHeartBeatStatus Send(IMessageContext context)
        {
            var activityContext = context.Extract(_tracer, _headers);

            using (var scope = _tracer.StartActivity("SendHeartBeat", ActivityKind.Internal, activityContext))
            {
                scope?.AddMessageIdTag(context);
                var status = _handler.Send(context);
                if (status.LastHeartBeatTime.HasValue)
                {
                    scope?.SetTag("HeartBeatValue", status.LastHeartBeatTime.Value.ToString(System.Globalization.CultureInfo.InvariantCulture));
                }
                return(status);
            }
        }
Пример #6
0
        /// <summary>
        /// Sends the heart beat.
        /// </summary>
        private void SendHeartBeatInternal()
        {
            if (IsDisposed)
            {
                return;
            }

            if (Running)
            {
                return;
            }

            if (Stopped)
            {
                return;
            }

            try
            {
                lock (_runningLocker)
                {
                    if (IsDisposed)
                    {
                        return;
                    }

                    if (Running)
                    {
                        return;
                    }

                    if (Stopped)
                    {
                        return;
                    }

                    Running = true;
                    var status = _sendHeartbeat.Send(_context);
                    if (status.LastHeartBeatTime.HasValue)
                    {
                        _context.WorkerNotification.HeartBeat.Status = status;
                        _logger.TraceFormat("Set heartbeat for message {0}", status.MessageId.Id.Value);
                    }
                    else
                    {
                        _logger.DebugFormat(
                            "Failed to set heartbeat for message ID {0}; since no exception was generated, this probably means that the record no longer exists",
                            status.MessageId.Id.Value);
                    }
                }
            }
            // ReSharper disable once UncatchableException
            catch (ThreadAbortException error)
            {
                if (_logger.IsWarnEnabled())
                {
                    _logger.WarnException(
                        "The worker thread has been aborted",
                        error);
                }
                lock (_runningLocker)
                {
                    _context.WorkerNotification.HeartBeat.SetError(error);
                }
                SetCancel();
            }
            catch (Exception error)
            {
                if (_logger.IsErrorEnabled())
                {
                    _logger.ErrorException(
                        "An error has occurred while updating the heartbeat field for a record that is being processed",
                        error);
                }
                lock (_runningLocker)
                {
                    _context.WorkerNotification.HeartBeat.SetError(error);
                }
                SetCancel();
            }
            finally
            {
                Running = false;
            }
        }
Пример #7
0
        /// <summary>
        /// Sends the heart beat.
        /// </summary>
        private void SendHeartBeatInternal()
        {
            if (IsDisposed)
            {
                return;
            }

            if (Running)
            {
                return;
            }

            if (Stopped)
            {
                return;
            }

            try
            {
                lock (_runningLocker)
                {
                    if (IsDisposed)
                    {
                        return;
                    }

                    if (Running)
                    {
                        return;
                    }

                    if (Stopped)
                    {
                        return;
                    }

                    Running = true;
                    var status = _sendHeartbeat.Send(_context);
                    if (status.LastHeartBeatTime.HasValue)
                    {
                        _context.WorkerNotification.HeartBeat.Status = status;
                        _logger.LogTrace($"Set heartbeat for message {status.MessageId.Id.Value}");
                    }
                    else
                    {
                        _logger.LogDebug(
                            $"Failed to set heartbeat for message ID {status.MessageId.Id.Value}; since no exception was generated, this probably means that the record no longer exists");
                    }
                }
            }
            // ReSharper disable once UncatchableException
            catch (ThreadAbortException error)
            {
                _logger.LogWarning(
                    "The worker thread has been aborted");

                lock (_runningLocker)
                {
                    _context.WorkerNotification.HeartBeat.SetError(error);
                }

                SetCancel();
            }
            catch (Exception error)
            {
                _logger.LogError(
                    $"An error has occurred while updating the heartbeat field for a record that is being processed{System.Environment.NewLine}{error}");

                lock (_runningLocker)
                {
                    _context.WorkerNotification.HeartBeat.SetError(error);
                }

                SetCancel();
            }
            finally
            {
                Running = false;
            }
        }
Пример #8
0
 private void OnTimedEvent(object sender, ElapsedEventArgs e)
 {
     m_sendHeartBeat.Send();
 }