Skip to content
This repository has been archived by the owner on Mar 9, 2021. It is now read-only.

Commit

Permalink
#280 Retry tumblr api request if answer is empty
Browse files Browse the repository at this point in the history
Reties the tumblr blog api v1 request if the server returns an empty HTTP-200 answer.
  • Loading branch information
johanneszab committed Nov 1, 2018
1 parent e4a6c7d commit df76a36
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public override async Task IsBlogOnlineAsync()
{
try
{
await GetApiPageAsync(0);
await GetApiPageWithRetryAsync(0);
blog.Online = true;
}
catch (WebException webException)
Expand Down Expand Up @@ -131,7 +131,7 @@ private async Task UpdateMetaInformation()
return;
}

string document = await GetApiPageAsync(0);
string document = await GetApiPageWithRetryAsync(0);
var response = ConvertJsonToClass<TumblrApiJson>(document);

blog.Title = response.tumblelog?.title;
Expand Down Expand Up @@ -229,6 +229,20 @@ private async Task<string> GetApiPageAsync(int pageId)
return await GetRequestAsync(url);
}

private async Task<string> GetApiPageWithRetryAsync(int pageId)
{
string page = string.Empty;
var attemptCount = 0;

do
{
page = await GetApiPageAsync(pageId);
attemptCount++;
} while (string.IsNullOrEmpty(page) && (attemptCount < shellService.Settings.MaxNumberOfRetries));

return page;
}

private async Task UpdateTotalPostCountAsync()
{
try
Expand Down Expand Up @@ -260,7 +274,7 @@ private async Task UpdateTotalPostCountAsync()

private async Task UpdateTotalPostCount()
{
string document = await GetApiPageAsync(0);
string document = await GetApiPageWithRetryAsync(0);
var response = ConvertJsonToClass<TumblrApiJson>(document);
int totalPosts = response.posts_total;
blog.Posts = totalPosts;
Expand Down Expand Up @@ -297,7 +311,7 @@ private async Task<ulong> GetHighestPostIdAsync()

private async Task<ulong> GetHighestPostId()
{
string document = await GetApiPageAsync(0);
string document = await GetApiPageWithRetryAsync(0);
var response = ConvertJsonToClass<TumblrApiJson>(document);

ulong highestId;
Expand Down Expand Up @@ -355,7 +369,7 @@ private async Task<Tuple<ulong, bool>> GetUrlsAsync()
{
try
{
string document = await GetApiPageAsync(pageNumber);
string document = await GetApiPageWithRetryAsync(pageNumber);
var response = ConvertJsonToClass<TumblrApiJson>(document);

completeGrab = CheckPostAge(response);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,21 @@ namespace TumblThree.Applications.Properties
public sealed class AppSettings : IExtensibleDataObject
{
private static readonly string[] blogTypes =
new string[]
{
Resources.BlogTypesNone, Resources.BlogTypesAll, Resources.BlogTypesOnceFinished, Resources.BlogTypesNeverFinished
};

private static readonly string[] imageSizes =
new string[]
{
"raw", "1280", "500", "400", "250", "100", "75"
};

private static readonly string[] videoSizes =
new string[]
{
"1080", "480"
};

private static string[] tumblrHosts =
new string[]
{
"data.tumblr.com"
};
Expand Down Expand Up @@ -262,7 +258,7 @@ private void Initialize()
LimitConnections = true;
MaxConnections = 90;
ConnectionTimeInterval = 60;
MaxNumberOfRetries = 10;
MaxNumberOfRetries = 3;
ProgessUpdateInterval = 200;
Bandwidth = 0;
BufferSize = 512;
Expand Down

0 comments on commit df76a36

Please sign in to comment.