Example #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BackgroundCommandEventRepositoryDispatcherDecorator"/> class.
 /// </summary>
 /// <param name="wrappedDispatcher">The wrapped <see cref="IBackgroundDispatcher"/>.</param>
 /// <param name="repository">The <see cref="IBackgroundCommandEventRepository"/>.</param>
 public BackgroundCommandEventRepositoryDispatcherDecorator(
     IBackgroundDispatcher wrappedDispatcher,
     IBackgroundCommandEventRepository repository)
 {
     _wrappedDispatcher = wrappedDispatcher ?? throw new ArgumentNullException(nameof(wrappedDispatcher));
     _repository        = repository ?? throw new ArgumentNullException(nameof(repository));
 }
Example #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BackgroundCommandEventRepositoryProcessorDecorator"/> class.
 /// </summary>
 /// <param name="wrappedProcessor">The wrapped <see cref="IBackgroundProcessor"/>.</param>
 /// <param name="repository">The <see cref="IBackgroundCommandEventRepository"/>.</param>
 public BackgroundCommandEventRepositoryProcessorDecorator(
     IBackgroundProcessor wrappedProcessor,
     IBackgroundCommandEventRepository repository)
 {
     _wrappedProcessor = wrappedProcessor ?? throw new ArgumentNullException(nameof(wrappedProcessor));
     _repository       = repository ?? throw new ArgumentNullException(nameof(repository));
 }
        public async Task <IActionResult> GetCommandStatus(
            [FromRoute] string id,
            [FromServices] IBackgroundCommandEventRepository repository)
        {
            var latestEvent = await repository.GetLatestEventForCommandId(id);

            if (latestEvent is null)
            {
                return(NotFound());
            }

            switch (latestEvent.Status)
            {
            case BackgroundCommandEventStatus.Dispatched:
            case BackgroundCommandEventStatus.Processing:
                // Indicate the desired polling frequency, in seconds.
                Response.Headers.Add("Retry-After", "10");
                return(NoContent());

            case BackgroundCommandEventStatus.Processed:
                // Once executed, redirect to the output.
                return(this.SeeOther(Url.RouteUrl(nameof(GetCommandOutput), new { id })));

            default:
                return(StatusCode(StatusCodes.Status500InternalServerError));
            }
        }