public ObjectResult Start([FromBody] string fileUrl) { if (repository.FindAllUnarchived().Any(x => x.FileUrl == fileUrl)) { logger.LogWarning(fileUrl + ": url already exists"); return(StatusCode(400, DownloadItemActionError.DuplicateDownload)); } var item = new DownloadItem { OwnerId = User.GetId(), FileUrl = fileUrl }; if (!service.StartDownload(item, out var error)) { switch (error) { case DownloadItemActionError.StartDownloadFailure: return(StatusCode(500, error)); case DownloadItemActionError.DownloadabilityFailure: return(StatusCode(404, error)); case DownloadItemActionError.UrlNotHandled: return(StatusCode(400, error)); } } return(Created("/start", item)); }
public Task Invoke() { //todo: check if no download pendings logger.LogInformation("[ConsumeFeedJob] Start"); var showRssItem = showRssItemRepository.FindFirstQueuedItem(); if (showRssItem == null) { logger.LogInformation("[ConsumeFeedJob] 0 item to consume"); return(Task.CompletedTask); } logger.LogInformation($"[ConsumeFeedJob] 1 item: {showRssItem.Title}"); var daemonUser = userRepository.GetDaemonUser(); var downloadItem = new DownloadItem { OwnerId = daemonUser.Id, FileUrl = showRssItem.Link }; if (!downloadItemService.StartDownload(downloadItem, out var error)) { logger.LogError("[ConsumeFeedJob] Failed: " + error); return(Task.CompletedTask); } logger.LogInformation("[ConsumeFeedJob] Succeeded"); showRssItem.DownloadItem = downloadItem; showRssItemRepository.Update(showRssItem); logger.LogInformation("[ConsumeFeedJob] Updated database"); return(Task.CompletedTask); }