public override async Task HandleItemAsync(WorkItemContext context) { var wi = context.GetData <RemoveProjectWorkItem>(); using (Log.BeginScope(new ExceptionlessState().Organization(wi.OrganizationId).Project(wi.ProjectId))) { Log.LogInformation("Received remove project work item for: {0} Reset Data: {1}", wi.ProjectId, wi.Reset); await context.ReportProgressAsync(0, "Starting deletion...").AnyContext(); var project = await _projectRepository.GetByIdAsync(wi.ProjectId).AnyContext(); if (project == null) { await context.ReportProgressAsync(100, wi.Reset? "Project data reset" : "Project deleted").AnyContext(); return; } if (!wi.Reset) { await context.ReportProgressAsync(20, "Removing tokens").AnyContext(); await _tokenRepository.RemoveAllByProjectIdAsync(project.OrganizationId, project.Id).AnyContext(); await context.ReportProgressAsync(40, "Removing web hooks").AnyContext(); await _webHookRepository.RemoveAllByProjectIdAsync(project.OrganizationId, project.Id).AnyContext(); } await context.ReportProgressAsync(60, "Resetting project data").AnyContext(); await _eventRepository.RemoveAllByProjectIdAsync(project.OrganizationId, project.Id).AnyContext(); await _stackRepository.RemoveAllByProjectIdAsync(project.OrganizationId, project.Id).AnyContext(); if (!wi.Reset) { await context.ReportProgressAsync(80, "Removing project").AnyContext(); await _projectRepository.RemoveAsync(project.Id).AnyContext(); } await context.ReportProgressAsync(100, wi.Reset? "Project data reset" : "Project deleted").AnyContext(); } }
private async Task RemoveProjectsAsync(Project project, JobContext context) { _logger.LogInformation("Removing project: {Project} ({ProjectId})", project.Name, project.Id); await _tokenRepository.RemoveAllByProjectIdAsync(project.OrganizationId, project.Id).AnyContext(); await _webHookRepository.RemoveAllByProjectIdAsync(project.OrganizationId, project.Id).AnyContext(); await RenewLockAsync(context).AnyContext(); long removedEvents = await _eventRepository.RemoveAllByProjectIdAsync(project.OrganizationId, project.Id).AnyContext(); await RenewLockAsync(context).AnyContext(); long removedStacks = await _stackRepository.RemoveAllByProjectIdAsync(project.OrganizationId, project.Id).AnyContext(); await _projectRepository.RemoveAsync(project).AnyContext(); _logger.LogInformation("Removed project: {Project} ({ProjectId}), Removed {RemovedStacks} Stacks, {RemovedEvents} Events", project.Name, project.Id, removedStacks, removedEvents); }
private async Task RemoveProjectsAsync(Project project, JobContext context) { _logger.RemoveProjectStart(project.Name, project.Id); await _tokenRepository.RemoveAllByProjectIdAsync(project.OrganizationId, project.Id).AnyContext(); await _webHookRepository.RemoveAllByProjectIdAsync(project.OrganizationId, project.Id).AnyContext(); await RenewLockAsync(context).AnyContext(); long removedEvents = await _eventRepository.RemoveAllByProjectIdAsync(project.OrganizationId, project.Id).AnyContext(); await RenewLockAsync(context).AnyContext(); long removedStacks = await _stackRepository.RemoveAllByProjectIdAsync(project.OrganizationId, project.Id).AnyContext(); await _projectRepository.RemoveAsync(project).AnyContext(); _logger.RemoveProjectComplete(project.Name, project.Id, removedStacks, removedEvents); }