/// <summary> /// Polls a thread, and passes it to the consumer if the thread has been detected as updated. /// </summary> /// <param name="token">The cancellation token associated with this request.</param> /// <param name="board">The board of the thread.</param> /// <param name="threadNumber">The post number of the thread to poll.</param> /// <param name="client">The <see cref="HttpClientProxy"/> to use for the poll request.</param> /// <returns></returns> private async Task <ThreadUpdateTaskResult> ThreadUpdateTask(CancellationToken token, string workerId, string board, ulong threadNumber, HttpClientProxy client) { try { Program.Log($"{workerId,-2}: Polling thread /{board}/{threadNumber}", true); var response = await YotsubaApi.GetThread(board, threadNumber, client.Client, null, token); token.ThrowIfCancellationRequested(); switch (response.ResponseType) { case ResponseType.Ok: Program.Log($"{workerId,-2}: Downloading changes from thread /{board}/{threadNumber}", true); var images = await ThreadConsumer.ConsumeThread(response.Data, board); if (response.Data.OriginalPost.Archived == true) { Program.Log($"{workerId,-2}: Thread /{board}/{threadNumber} has been archived", true); await ThreadConsumer.ThreadUntracked(threadNumber, board, false); } return(new ThreadUpdateTaskResult(true, images, response.Data.OriginalPost.Archived == true ? ThreadUpdateStatus.Archived : ThreadUpdateStatus.Ok, response.Data.Posts.Length)); case ResponseType.NotModified: return(new ThreadUpdateTaskResult(true, new QueuedImageDownload[0], ThreadUpdateStatus.NotModified, response.Data.Posts.Length)); case ResponseType.NotFound: Program.Log($"{workerId,-2}: Thread /{board}/{threadNumber} has been pruned or deleted", true); await ThreadConsumer.ThreadUntracked(threadNumber, board, true); return(new ThreadUpdateTaskResult(true, new QueuedImageDownload[0], ThreadUpdateStatus.Deleted, 0)); default: throw new ArgumentOutOfRangeException(); } } catch (Exception exception) { Program.Log($"ERROR: Could not poll or update thread /{board}/{threadNumber}. Will try again next board update\nClient name: {client.Name}\nException: {exception}"); return(new ThreadUpdateTaskResult(false, new QueuedImageDownload[0], ThreadUpdateStatus.Error, 0)); } }
private async Task <bool> ThreadUpdateTask(CancellationToken token, string board, ulong threadNumber) { try { await APISemaphore.WaitAsync(token); Program.Log($"Polling thread /{board}/{threadNumber}"); var response = await YotsubaApi.GetThread(board, threadNumber, null, token); switch (response.ResponseType) { case YotsubaResponseType.Ok: Program.Log($"Downloading changes from thread /{board}/{threadNumber}"); await ThreadConsumer.ConsumeThread(response.Thread, board); if (response.Thread.OriginalPost.Archived == true) { Program.Log($"Thread /{board}/{threadNumber} has been archived"); await ThreadConsumer.ThreadUntracked(threadNumber, board, false); } return(true); case YotsubaResponseType.NotModified: return(true); case YotsubaResponseType.NotFound: Program.Log($"Thread /{board}/{threadNumber} has been pruned or deleted"); await ThreadConsumer.ThreadUntracked(threadNumber, board, true); return(true); default: throw new ArgumentOutOfRangeException(); } } catch (Exception exception) { Program.Log($"ERROR: Could not poll or update thread /{board}/{threadNumber}. Will try again next board update\nException: {exception}"); return(false); } }
/// <summary> /// Polls a thread, and passes it to the consumer if the thread has been detected as updated. /// </summary> /// <param name="token">The cancellation token associated with this request.</param> /// <param name="board">The board of the thread.</param> /// <param name="threadNumber">The post number of the thread to poll.</param> /// <param name="client">The <see cref="HttpClientProxy"/> to use for the poll request.</param> /// <returns></returns> private async Task <(bool success, IList <QueuedImageDownload> imageDownloads)> ThreadUpdateTask(CancellationToken token, string board, ulong threadNumber, HttpClientProxy client) { try { Program.Log($"Polling thread /{board}/{threadNumber}"); var response = await YotsubaApi.GetThread(board, threadNumber, client.Client, null, token); switch (response.ResponseType) { case ResponseType.Ok: Program.Log($"Downloading changes from thread /{board}/{threadNumber}"); var images = await ThreadConsumer.ConsumeThread(response.Data, board); if (response.Data.OriginalPost.Archived == true) { Program.Log($"Thread /{board}/{threadNumber} has been archived"); await ThreadConsumer.ThreadUntracked(threadNumber, board, false); } return(true, images); case ResponseType.NotModified: return(true, new QueuedImageDownload[0]); case ResponseType.NotFound: Program.Log($"Thread /{board}/{threadNumber} has been pruned or deleted"); await ThreadConsumer.ThreadUntracked(threadNumber, board, true); return(true, new QueuedImageDownload[0]); default: throw new ArgumentOutOfRangeException(); } } catch (Exception exception) { Program.Log($"ERROR: Could not poll or update thread /{board}/{threadNumber}. Will try again next board update\nClient name: {client.Name}\nException: {exception}"); return(false, null); } }