Skip to content

Commit

Permalink
Progress and write exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidKarlas committed Nov 25, 2023
1 parent 6d539be commit e77cac9
Showing 1 changed file with 25 additions and 7 deletions.
32 changes: 25 additions & 7 deletions OsmGursBuildingImport/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,21 @@ static async Task<int> Main(string[] args)
{
while (true)
{
var restartToken = new CancellationTokenSource();
int dayOfWeek = (int)DateTime.UtcNow.DayOfWeek;
DateTime nextSunday6AM = DateTime.UtcNow.AddDays(7 - dayOfWeek).Date.AddHours(6);
restartToken.CancelAfter(nextSunday6AM - DateTime.UtcNow);
var result = await Process(args, restartToken.Token);
if (result != 0)
return result;
try
{
var restartToken = new CancellationTokenSource();
int dayOfWeek = (int)DateTime.UtcNow.DayOfWeek;
DateTime nextSunday6AM = DateTime.UtcNow.AddDays(7 - dayOfWeek).Date.AddHours(6);
restartToken.CancelAfter(nextSunday6AM - DateTime.UtcNow);
var result = await Process(args, restartToken.Token);
if (result != 0)
return result;
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
await Task.Delay(TimeSpan.FromMinutes(1));
}
}
}

Expand Down Expand Up @@ -82,8 +90,18 @@ static async Task<int> Process(string[] args, CancellationToken cancellationToke

var fullFileCacheFolder = Path.Combine(cacheDir, "full");
Directory.CreateDirectory(fullFileCacheFolder);
int allAreasCount = gursData.ProcessingAreas.Count;
int lastPercent = 0;
int processedAreas = 0;
Parallel.ForEach(gursData.ProcessingAreas, (processingArea) => {
CreateFull(processingArea.Value, fullFileCacheFolder);
var num = Interlocked.Increment(ref processedAreas);
var percent = (int)((num / (double)allAreasCount) * 100);
if (percent != lastPercent)
{
lastPercent = percent;
Console.WriteLine($"Generated {percent}% of .full.osm.bz2 files.");
}
});
Console.WriteLine("Generated all .full.osm.bz2 files.");

Expand Down

0 comments on commit e77cac9

Please sign in to comment.