/// <summary> /// Processes a single project task. /// </summary> /// <remarks> /// First this syncs the task with the data store, then /// the task is executed, then the success or failure is /// synced with the data store. /// </remarks> /// <param name="task">The project task.</param> /// <param name="token">The cancellation token.</param> public async Task ProcessProjectTaskAsync(ProjectTask task, CancellationToken token) { if (task == null) { throw new ArgumentNullException(nameof(task)); } if (token == null) { throw new ArgumentNullException(nameof(token)); } // TODO This should be transactional --> scope? var taskCreatedId = await _projectTaskRepository.CreateAsync(task, token); try { await(task.ProjectTaskType switch { ProjectTaskType.UploadAudio => _uploadAudioExecuter.ExecuteUploadAudioAsync(task, token), ProjectTaskType.BackupFull => throw new NotImplementedException(), _ => throw new InvalidOperationException(nameof(task.ProjectTaskType)), }); await _projectTaskRepository.MarkStatusAsync(taskCreatedId, ProjectTaskStatus.Done, token); _logger.LogTrace($"Executed project task {task.Id} of type {task.ProjectTaskType}"); }