public async Task <IActionResult> FileUpload(IFormFile file) { var sw = Stopwatch.StartNew(); if (file is object && file.Length > 0) { var fileName = Path.GetTempFileName(); // Upload to a temp file path await using var stream = new FileStream(fileName, FileMode.Create); await file.CopyToAsync(stream); stream.Position = 0; await _resultProcessor.ProcessAsync(stream); System.IO.File.Delete(fileName); // Delete the temp file } sw.Stop(); _logger.LogInformation($"Time taken for result upload and processing " + $"was {sw.ElapsedMilliseconds}ms."); return(RedirectToAction("UploadComplete")); }
public async Task ProcessScoresFromMessageAsync(Message message, CancellationToken cancellationToken = default) { var objectKeys = _s3EventNotificationMessageParser.Parse(message); foreach (var objectKey in objectKeys) { // future - SQS is at least once delivery, If the downstream processor is not idempotent // this processor should be. It could store hashes of the messages/files that have successfully processed. // Skipping those so there is not duplicate of scores and stats // load from S3 stream await using var dataStream = await _s3DataProvider.GetStreamAsync(objectKey, cancellationToken); // process the data await _resultProcessor.ProcessAsync(dataStream, cancellationToken); } // delete the SQS message // we don't pass cancellation as we want to ensure we delete the message if we have completely processed it, before we shutdown await _sqsMessageDeleter.DeleteMessageAsync(message); }