public IActionResult CreateResource([FromBody] DiscreteLogarithmCreateDto createDto) { var result = base.CreateResource <DiscreteLogarithmCreateDto, DiscreteLogarithmGetDto>(createDto); if (CreatedResource == null) { return(result); } if (User.Identity.IsAuthenticated) { CreatedResource.SubscriberId = User.Claims.First(claim => claim.Type == JwtClaimTypes.Subject).Value; } CreatedResource.JobId = CreatedResource.StartJobService(); ResourceDataService.Update(CreatedResource); ResourceDataService.SaveChanges(); ExecutionLogger.SetExecutionId(CreatedResource.Id); ExecutionLogger.Info("Enqueued for execution."); return(result); }
protected async Task FetchItemsAsync(IEnumerable <ContainerItem> containerItems, CancellationToken token) { var itemsToDownload = new List <ContainerItem>(); foreach (ContainerItem item in containerItems) { if (item.ItemType == ItemType.Folder) { string localDirectory = ConvertToLocalPath(item); FileSystemManager.EnsureDirectoryExists(localDirectory); } else if (item.ItemType == ItemType.File) { string localPath = ConvertToLocalPath(item); ExecutionLogger.Info(StringUtil.Loc("RMCopyingFile", item.Path, localPath)); _totalFiles++; if (item.FileLength == 0) { CreateEmptyFile(localPath); _newEmptyFiles++; } else { itemsToDownload.Add(item); } } else { throw new NotSupportedException(StringUtil.Loc("RMContainerItemNotSupported", item.ItemType)); } } if (_totalFiles == 0) { ExecutionLogger.Warning(StringUtil.Loc("RMArtifactEmpty")); } if (itemsToDownload.Count > 0) { var cancellationTokenSource = new CancellationTokenSource(); CancellationToken cancellationToken = CancellationTokenSource.CreateLinkedTokenSource(token, cancellationTokenSource.Token).Token; // Used to limit the number of concurrent downloads. SemaphoreSlim downloadThrottle = new SemaphoreSlim(ContainerFetchEngineOptions.ParallelDownloadLimit); Stopwatch watch = Stopwatch.StartNew(); LinkedList <Task> remainingDownloads = new LinkedList <Task>(); foreach (ContainerItem ticketedItem in itemsToDownload) { _bytesDownloaded += ticketedItem.FileLength; Task downloadTask = DownloadItemAsync(downloadThrottle, ticketedItem, cancellationToken); if (downloadTask.IsCompleted) { // don't wait to throw for faulted tasks. await downloadTask.ConfigureAwait(false); } else { remainingDownloads.AddLast(downloadTask); } } try { // Monitor and log the progress of the download tasks if they take over a few seconds. await LogProgressAsync(remainingDownloads).ConfigureAwait(false); cancellationTokenSource.Dispose(); } catch (Exception) { cancellationTokenSource.Cancel(); await Task.WhenAll(remainingDownloads); cancellationTokenSource.Dispose(); throw; } _elapsedDownloadTime += watch.Elapsed; } _downloadedFiles += itemsToDownload.Count; }