/// <inheritdoc />
        public async Task ProcessAsync(IBackgroundCommand command, CancellationToken cancellationToken = default)
        {
            if (command == null)
            {
                throw new ArgumentNullException(nameof(command));
            }

            try
            {
                var now       = DateTimeOffset.UtcNow;
                var stopwatch = Stopwatch.StartNew();
                await _wrappedProcessor.ProcessAsync(command, cancellationToken);

                stopwatch.Stop();
                var eventTelemetry = new EventTelemetry(BackgroundCommandProcessedEventName);
                eventTelemetry.Properties.Add(nameof(command.Id), command.Id);
                eventTelemetry.Properties.Add(nameof(command.Timestamp), command.Timestamp.ToString("O", CultureInfo.InvariantCulture));
                eventTelemetry.Metrics.Add(BackgroundCommandProcessTimeMetricName, stopwatch.ElapsedMilliseconds);
                eventTelemetry.Metrics.Add(BackgroundCommandLatencyTimeMetricName, now.Subtract(command.Timestamp).TotalMilliseconds);
                _options.Value.AdditionalProperties?.Invoke(command, eventTelemetry.Properties);
                _telemetryClient.TrackEvent(eventTelemetry);
            }
            catch (Exception ex)
            {
                var exceptionTelemetry = new ExceptionTelemetry(ex);
                exceptionTelemetry.Properties.Add(nameof(command.Id), command.Id);
                exceptionTelemetry.Properties.Add(nameof(command.Timestamp), command.Timestamp.ToString("O", CultureInfo.InvariantCulture));
                _options.Value.AdditionalProperties?.Invoke(command, exceptionTelemetry.Properties);
                _telemetryClient.TrackException(exceptionTelemetry);
                throw;
            }
        }
 /// <inheritdoc />
 public async Task ProcessAsync(IBackgroundCommand command, CancellationToken cancellationToken = default)
 {
     try
     {
         await _wrappedProcessor.ProcessAsync(command, cancellationToken);
     }
     finally
     {
         _awaiter.Signal();
     }
 }
        /// <summary>
        /// Handles the <paramref name="message"/> from the queue trigger.
        /// </summary>
        /// <param name="message">The message to handle.</param>
        /// <param name="cancellationToken">The <see cref="CancellationToken"/>.</param>
        /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
        public async Task HandleAsync(string message, CancellationToken cancellationToken = default)
        {
            if (string.IsNullOrEmpty(message))
            {
                throw new ArgumentNullException(nameof(message));
            }

            var command = await _serializer.DeserializeAsync(message);

            await _processor.ProcessAsync(command, cancellationToken);
        }
コード例 #4
0
        /// <inheritdoc />
        public async Task ProcessAsync(IBackgroundCommand command, CancellationToken cancellationToken = default)
        {
            try
            {
                await _repository.Add(new BackgroundCommandEvent(command, BackgroundCommandEventStatus.Processing, DateTimeOffset.UtcNow), cancellationToken);

                await _wrappedProcessor.ProcessAsync(command, cancellationToken);

                await _repository.Add(new BackgroundCommandEvent(command, BackgroundCommandEventStatus.Processed, DateTimeOffset.UtcNow));
            }
            catch (Exception ex)
            {
                await _repository.Add(new BackgroundCommandEvent(command, BackgroundCommandEventStatus.Error, DateTimeOffset.UtcNow, ex));

                throw;
            }
        }