public void Deve_atualizar_status_executado() { var recycler = new Recycler(); recycler.Executed(); recycler.UpdatedDate.Should().HaveValue(); recycler.Status.Should().Be(JobStatus.Executed); }
public async Task Retornar_status_nao_rodando_quando_existir_job_parado() { var lastRecycler = new Recycler(); lastRecycler.Executed(); _recyclerRepository.Setup(x => x.GetLastRun()).ReturnsAsync(lastRecycler); var query = new GetRecyclerStatusQuery(); var result = await _handler.Handle(query, CancellationToken.None); result.Should().Be(JobStatus.NotRunning); }
public async Task <Unit> Handle(RecyclerStartCommand request, CancellationToken cancellationToken) { _logger.LogInformation($"Iniciando processo de reciclagem de vídeos com mais de {request.Days} dias."); var recycler = new Recycler(); _recyclerRepository.Add(recycler); await _recyclerRepository.SaveChangesAsync(); var servers = await _serverRepository.GetAllAsync(); foreach (var server in servers) { var date = Clock.Now.Date.AddDays(-request.Days); var oldVideos = server.Videos.Where(x => x.CreatedDate.Date <= date); _logger.LogInformation($"Reciclando {oldVideos.Count()} vídeos do servidor {server.Name}."); foreach (var video in oldVideos) { await _videoRepository.RemoveContent(video.Path); _serverRepository.RemoveVideo(video); _logger.LogInformation($"Vídeo {video.Description} removido do servidor {server.Name}"); } } recycler.Executed(); await _recyclerRepository.SaveChangesAsync(); return(Unit.Value); }