Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
# Conflicts:
#	Server/ReplayParser.cs
  • Loading branch information
Simyon264 committed Mar 21, 2024
2 parents 4798003 + b8381e2 commit e669a24
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 35 deletions.
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Replay Browser

This is the repository for a replay browser for Space Station 14. The replay browser downloads replays from the provided paths, parses them, and then finally inserts it into the provided DB.
You can view the deployed website [here](https://replay.unstablefoundation.de/)

## Setup

Setting up a dev env is simple.
These instructions assume that you have a postgres database set up.

1. Clone the repository.
2. Set up the appsettings file.
Create a file named `appsettings.Secret.json` in the server project.
This is where you can put your connection string for the postgres DB.
3. Run both the server and client using `dotnet`. The server will now download a lot of replays. This will take some time and it will use about 50 Mbps. You can keep using your computer during this time.

## Screenshots
<details>
<summary>View</summary>

![image](https://github.com/Simyon264/ReplayBrowser/assets/63975668/f46c954f-cab1-4b95-be62-ee4d79329305)

![image](https://github.com/Simyon264/ReplayBrowser/assets/63975668/c1e7b857-d643-4ca2-a69d-c62f3bbc383e)

![image](https://github.com/Simyon264/ReplayBrowser/assets/63975668/3efa2506-cc35-44f3-91d5-d99cdcba7a66)

![image](https://github.com/Simyon264/ReplayBrowser/assets/63975668/9bf1753d-ca22-466b-89ab-9f4aba186666)

![image](https://github.com/Simyon264/ReplayBrowser/assets/63975668/c4b2212c-9644-448e-9458-551d6e5b6edc)
</details>
65 changes: 30 additions & 35 deletions Server/ReplayParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,12 @@ public static Task AddParsedReplayToDb(string replay)

public static async Task ConsumeQueue(CancellationToken token)
{
while (!token.IsCancellationRequested)
// Consume the queue.
while (Queue.Count > 0)
{
// Consume the queue.
while (Queue.Count > 0)
{
var timeoutToken = new CancellationTokenSource(10000);
var tokenSource = CancellationTokenSource.CreateLinkedTokenSource(token, timeoutToken.Token);
var startTime = DateTime.Now;
var timeoutToken = new CancellationTokenSource(10000);
var tokenSource = CancellationTokenSource.CreateLinkedTokenSource(token, timeoutToken.Token);
var startTime = DateTime.Now;

// Since replays are like 200mb long, we want to parrallelize this.
var tasks = new List<Task>();
Expand Down Expand Up @@ -105,38 +103,35 @@ public static async Task ConsumeQueue(CancellationToken token)
parsedReplay.Date = date.ToUniversalTime();
}
// One more check to see if it's already in the database.
if (await IsReplayParsed(replay))
{
return;
}
await AddReplayToDb(parsedReplay);
await AddParsedReplayToDb(replay);
Log.Information("Parsed " + replay);
}
catch (Exception e)
// One more check to see if it's already in the database.
if (await IsReplayParsed(replay))
{
Log.Error(e, "Error while parsing " + replay);
return;
}
}, tokenSource.Token));
}
await AddReplayToDb(parsedReplay);
await AddParsedReplayToDb(replay);
Log.Information("Parsed " + replay);
}
catch (Exception e)
{
Log.Error(e, "Error while parsing " + replay);
}
}, tokenSource.Token));
}

// If the download takes too long, cancel it.
// 10 minutes should be enough
await Task.WhenAny(Task.WhenAll(tasks), Task.Delay(600000, token));
await timeoutToken.CancelAsync();
// Cancel the timeout token, so the background tasks cancel as well.
// If the download takes too long, cancel it.
// 10 minutes should be enough
await Task.WhenAny(Task.WhenAll(tasks), Task.Delay(600000, token));
await timeoutToken.CancelAsync();
// Cancel the timeout token, so the background tasks cancel as well.

// If we timed out, log a warning.
if (DateTime.Now - startTime > TimeSpan.FromMinutes(10))
{
Log.Warning("Parsing took too long for " + string.Join(", ", tasks.Select(x => x.Id)));
}
// If we timed out, log a warning.
if (DateTime.Now - startTime > TimeSpan.FromMinutes(10))
{
Log.Warning("Parsing took too long for " + string.Join(", ", tasks.Select(x => x.Id)));
}

await Task.Delay(5000, token);
}
}
}

/// <summary>
Expand Down Expand Up @@ -341,4 +336,4 @@ public static List<Replay> SearchReplays(SearchMode mode, string query, ReplayDb
throw new NotImplementedException();
}
}
}
}

0 comments on commit e669a24

Please sign in to comment.