Skip to content

Commit

Permalink
Export command now uses the searchAfter parameter which will allow fo…
Browse files Browse the repository at this point in the history
…r exporting more than 10k message
  • Loading branch information
ThomasArdal committed Nov 24, 2023
1 parent 8be02df commit da081a1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
4 changes: 2 additions & 2 deletions src/Elmah.Io.Cli/Elmah.Io.Cli.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Elmah.Io.Client" Version="5.0.66" />
<PackageReference Include="Elmah.Io.Client" Version="5.1.71-pre" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Spectre.Console" Version="0.47.0" />
<PackageReference Include="Spectre.Console" Version="0.48.0" />
<PackageReference Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />
<PackageReference Include="Tx.Windows" Version="3.0.6" />
</ItemGroup>
Expand Down
28 changes: 16 additions & 12 deletions src/Elmah.Io.Cli/ExportCommand.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Newtonsoft.Json;
using Elmah.Io.Client;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Spectre.Console;
using System;
Expand Down Expand Up @@ -52,11 +53,6 @@ internal static Command Create()
else
{
int messSum = startResult.Total.Value;
if (messSum > 10000)
{
AnsiConsole.MarkupLine("[#ffc936]Query returned more than 10,000 messages. The exporter will cap at 10,000 messages. Consider using the -DateFrom, -DateTo, and/or the -Query parameters to limit the search result.[/]");
messSum = 10000;
}
await AnsiConsole
.Progress()
Expand All @@ -71,18 +67,26 @@ await AnsiConsole
if (File.Exists(filename)) File.Delete(filename);
using (StreamWriter w = File.AppendText(filename))
{
int i = 0;
string searchAfter = null;
var firstMessage = true;
w.WriteLine("[");
while (i < messSum)
while (true)
{
var respons = await api.Messages.GetAllAsync(logId.ToString(), i / 10, 10, query, dateFrom, dateTo, includeHeaders);
foreach (Client.MessageOverview message in respons.Messages)
var response = await api.Messages.GetAllAsync(logId.ToString(), pageSize: 100, query: query, from: dateFrom, to: dateTo, includeHeaders: includeHeaders, searchAfter: searchAfter);
if (response.Messages.Count == 0)
{
task.Increment(task.MaxValue - task.Value);
task.StopTask();
break;
}
foreach (MessageOverview message in response.Messages)
{
if (!firstMessage) w.WriteLine(",");
firstMessage = false;
w.WriteLine(JToken.Parse(JsonConvert.SerializeObject(message)).ToString(Formatting.Indented));
i++;
if (i != messSum) w.WriteLine(",");
task.Increment(1);
}
searchAfter = response.SearchAfter;
}
w.WriteLine("]");
}
Expand Down

0 comments on commit da081a1

Please sign in to comment.