Beispiel #1
0
        public static void Completion <T>(
            ConfirmationLogger operation,
            ICommandDelivery <T> delivery,
            ICommandDeliveryResult result)
        {
            string resultString = null;

            switch (result)
            {
            case CompleteDeliveryResult <T> complete:
                resultString = "Complete";
                break;

            case RetryDeliveryResult <T> retry:
                resultString = "WillRetry";
                break;

            case CancelDeliveryResult <T> cancel:
                resultString = "Cancelled";
                break;
            }

            operation.Succeed(
                $"{{result}}: {messageTemplate}",
                resultString,
                delivery.Command,
                delivery.IdempotencyToken,
                delivery.DueTime,
                delivery.NumberOfPreviousAttempts);
        }
Beispiel #2
0
        public async Task <ICommandDeliveryResult> Receive(
            HandleCommand <T> handle,
            TimeSpan?timeout = null)
        {
            timeout = timeout ??
                      Settings.For <T> .Default.ReceiveTimeout;

            var stopAt = clock.Now() + timeout;

            ICommandDeliveryResult result = null;

            using (Subscribe(async delivery =>
            {
                result = await handle(delivery);
                return(result);
            }))
            {
                while (result == null &&
                       clock.Now() <= stopAt)
                {
                    var timeUntilNextActionIsDue = clock.TimeUntilNextActionIsDue;

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

                    await clock.Wait(timeUntilNextActionIsDue.Value);
                }
            }

            return(result);
        }