private void ObeyPayloadTimeout(Payload payload, PayloadQueue queue)
 {
     if (payload.TimeoutAt.HasValue && (DateTime.Now.Add(this._sleepInterval) >= payload.TimeoutAt.Value))
     {
         queue.Dequeue();
     }
 }
Example #2
0
        /// <summary>
        /// Processes the specified queue.
        /// </summary>
        /// <param name="queue">The queue.</param>
        /// <param name="response">The response.</param>
        /// <returns>PayloadBundle.</returns>
        private PayloadBundle Process(PayloadQueue queue, out RollbarResponse response)
        {
            response = null;

            PayloadBundle payloadBundle = GetFirstTransmittableBundle(queue);
            Payload       payload       = payloadBundle?.GetPayload();

            if (payload == null) // one more sanity check before proceeding further...
            {
                return(null);
            }

            if (queue.Logger?.Config != null && !queue.Logger.Config.Transmit)
            {
                response = new RollbarResponse();
                this.OnRollbarEvent(
                    new TransmissionOmittedEventArgs(queue.Logger, payload)
                    );
                return(payloadBundle);
            }

            try
            {
                response = queue.Client.PostAsJson(payloadBundle);
            }
            catch (System.Exception ex)
            {
                this.OnRollbarEvent(
                    new CommunicationErrorEventArgs(queue.Logger, payload, ex, 0)
                    );
                payloadBundle.Register(ex);
                throw;
            }

            if (response != null)
            {
                this.OnRollbarEvent(
                    new CommunicationEventArgs(queue.Logger, payload, response)
                    );
            }
            else
            {
                queue.Dequeue(); //we tried our best...
                payloadBundle.Register(new RollbarException(InternalRollbarError.DequeuingError, "Payload dropped!"));
            }

            return(payloadBundle);
        }
Example #3
0
        /// <summary>
        /// Gets the first transmittabl bundle.
        /// </summary>
        /// <param name="queue">The queue.</param>
        /// <returns>PayloadBundle.</returns>
        private PayloadBundle GetFirstTransmittableBundle(PayloadQueue queue)
        {
            PayloadBundle payloadBundle = null;

            bool ignorableBundle = false;

            do
            {
                payloadBundle = queue.Peek();
                if (payloadBundle == null)
                {
                    return(null); // the queue is already empty, nothing to process...
                }

                try
                {
                    ignorableBundle = (payloadBundle.Ignorable || payloadBundle.GetPayload() == null);
                }
                catch (System.Exception ex)
                {
                    RollbarErrorUtility.Report(
                        null,
                        payloadBundle,
                        InternalRollbarError.DequeuingError,
                        "While attempting to dequeue a payload bundle...",
                        ex,
                        payloadBundle
                        );
                    ignorableBundle = true; // since something is not kosher about this bundle/payload, it is wise to ignore one...
                }

                if (ignorableBundle)
                {
                    queue.Dequeue(); //throw away the ignorable...
                    this.OnRollbarEvent(
                        new PayloadDropEventArgs(queue.Logger, null, PayloadDropEventArgs.DropReason.IgnorablePayload)
                        );
                }
            }while (ignorableBundle);

            return(payloadBundle);
        }
        /// <summary>
        /// Processes the specified queue.
        /// </summary>
        /// <param name="queue">The queue.</param>
        /// <param name="response">The response.</param>
        /// <returns>PayloadBundle.</returns>
        private PayloadBundle Process(PayloadQueue queue, out RollbarResponse response)
        {
            response = null;

            PayloadBundle payloadBundle;
            Payload       payload = null;

            bool ignorableBundle = false;

            do
            {
                payloadBundle = queue.Peek();
                if (payloadBundle == null)
                {
                    return(null); // the queue is already empty, nothing to process...
                }

                try
                {
                    ignorableBundle = (payloadBundle.Ignorable || payloadBundle.GetPayload() == null);
                }
                catch (System.Exception ex)
                {
                    RollbarErrorUtility.Report(
                        null,
                        payloadBundle,
                        InternalRollbarError.DequeuingError,
                        "While attempting to dequeue a payload bundle...",
                        ex
                        );
                    ignorableBundle = true; // since something is not kosher about this bundle/payload, it is wise to ignore one...
                }

                if (ignorableBundle)
                {
                    queue.Dequeue(); //throw away the ignorable...
                }
                else
                {
                    payload = payloadBundle.GetPayload();
                }
            }while (ignorableBundle);

            if (payloadBundle == null || payload == null) // one more sanity check before proceeding further...
            {
                return(null);
            }

            int retries = this._totalRetries;

            while (retries > 0)
            {
                try
                {
                    response = queue.Client.PostAsJson(payloadBundle);
                }
                catch (WebException ex)
                {
                    retries--;
                    this.OnRollbarEvent(
                        new CommunicationErrorEventArgs(queue.Logger, payload, ex, retries)
                        );
                    continue;
                }
                catch (ArgumentNullException ex)
                {
                    retries = 0;
                    this.OnRollbarEvent(
                        new CommunicationErrorEventArgs(queue.Logger, payload, ex, retries)
                        );
                    continue;
                }
                catch (System.Exception ex)
                {
                    retries = 0;
                    this.OnRollbarEvent(
                        new CommunicationErrorEventArgs(queue.Logger, payload, ex, retries)
                        );
                    continue;
                }
                retries = 0;
            }

            if (response != null)
            {
                this.OnRollbarEvent(
                    new CommunicationEventArgs(queue.Logger, payload, response)
                    );
            }

            return(payloadBundle);
        }
        private PayloadBundle Process(PayloadQueue queue, out RollbarResponse response)
        {
            response = null;

            PayloadBundle payloadBundle = queue.Peek();

            while (payloadBundle != null && (payloadBundle.Ignorable || payloadBundle.GetPayload() == null))
            {
                queue.Dequeue();              //throw away the useless one...
                payloadBundle = queue.Peek(); //try next...
            }
            if (payloadBundle == null)
            {
                return(null); //no bundles to process...
            }

            Payload payload = payloadBundle.GetPayload();

            if (payload == null)
            {
                return(null);
            }

            int retries = this._totalRetries;

            while (retries > 0)
            {
                try
                {
                    response = queue.Client.PostAsJson(payloadBundle);
                }
                catch (WebException ex)
                {
                    retries--;
                    this.OnRollbarEvent(
                        new CommunicationErrorEventArgs(queue.Logger, payload, ex, retries)
                        );
                    continue;
                }
                catch (ArgumentNullException ex)
                {
                    retries = 0;
                    this.OnRollbarEvent(
                        new CommunicationErrorEventArgs(queue.Logger, payload, ex, retries)
                        );
                    continue;
                }
                catch (System.Exception ex)
                {
                    retries = 0;
                    this.OnRollbarEvent(
                        new CommunicationErrorEventArgs(queue.Logger, payload, ex, retries)
                        );
                    continue;
                }
                retries = 0;
            }

            if (response != null)
            {
                this.OnRollbarEvent(
                    new CommunicationEventArgs(queue.Logger, payload, response)
                    );
            }

            return(payloadBundle);
        }
Example #6
0
        /// <summary>
        /// Processes the specified queue.
        /// </summary>
        /// <param name="queue">The queue.</param>
        /// <param name="response">The response.</param>
        /// <returns>PayloadBundle.</returns>
        private PayloadBundle Process(PayloadQueue queue, out RollbarResponse response)
        {
            response = null;

            PayloadBundle payloadBundle;
            Payload       payload = null;

            bool ignorableBundle = false;

            do
            {
                payloadBundle = queue.Peek();
                if (payloadBundle == null)
                {
                    return(null); // the queue is already empty, nothing to process...
                }

                try
                {
                    ignorableBundle = (payloadBundle.Ignorable || payloadBundle.GetPayload() == null);
                }
                catch (System.Exception ex)
                {
                    RollbarErrorUtility.Report(
                        null,
                        payloadBundle,
                        InternalRollbarError.DequeuingError,
                        "While attempting to dequeue a payload bundle...",
                        ex,
                        payloadBundle
                        );
                    ignorableBundle = true; // since something is not kosher about this bundle/payload, it is wise to ignore one...
                }

                if (ignorableBundle)
                {
                    queue.Dequeue(); //throw away the ignorable...
                    this.OnRollbarEvent(
                        new PayloadDropEventArgs(queue.Logger, null, PayloadDropEventArgs.DropReason.IgnorablePayload)
                        );
                }
                else
                {
                    payload = payloadBundle.GetPayload();
                }
            }while (ignorableBundle);

            if (payloadBundle == null || payload == null) // one more sanity check before proceeding further...
            {
                return(null);
            }

            if (queue.Logger?.Config != null && !queue.Logger.Config.Transmit)
            {
                response = new RollbarResponse();
                this.OnRollbarEvent(
                    new TransmissionOmittedEventArgs(queue.Logger, payload)
                    );
                return(payloadBundle);
            }

            int retries = this._totalRetries;

            while (retries > 0)
            {
                try
                {
                    response = queue.Client.PostAsJson(payloadBundle);
                }
                catch (WebException ex)
                {
                    retries--;
                    this.OnRollbarEvent(
                        new CommunicationErrorEventArgs(queue.Logger, payload, ex, retries)
                        );
                    payloadBundle.Register(ex);
                    Thread.Sleep(this._sleepInterval); // wait a bit before we retry it...
                    continue;
                }
                catch (ArgumentNullException ex)
                {
                    retries = 0;
                    this.OnRollbarEvent(
                        new CommunicationErrorEventArgs(queue.Logger, payload, ex, retries)
                        );
                    payloadBundle.Register(ex);
                    continue;
                }
                catch (System.Exception ex)
                {
                    retries = 0;
                    this.OnRollbarEvent(
                        new CommunicationErrorEventArgs(queue.Logger, payload, ex, retries)
                        );
                    payloadBundle.Register(ex);
                    continue;
                }
                retries = 0;
            }

            if (response != null)
            {
                this.OnRollbarEvent(
                    new CommunicationEventArgs(queue.Logger, payload, response)
                    );
            }
            else
            {
                queue.Dequeue(); //we tried our best...
                payloadBundle.Register(new RollbarException(InternalRollbarError.DequeuingError, "Payload dropped!"));
            }

            return(payloadBundle);
        }