Skip to content

Commit

Permalink
feat(dotnet): add fireAndForget option
Browse files Browse the repository at this point in the history
  • Loading branch information
AndriiAndreiev committed Dec 5, 2024
1 parent 80e7d23 commit 959fe8a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
2 changes: 2 additions & 0 deletions packages/dotnet/ReadMe/ConfigValues.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,7 @@ public class Options
public int bufferLength { get; set; } = 1;

public string baseLogUrl { get; set; } = "https://example.readme.com";

public bool fireAndForget { get; set; } = true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public ReadMeApiCaller(string harJsonObject, string apiKey)
this.apiKey = apiKey;
}

public void SendHarObjToReadMeApi()
public void SendHarObjToReadMeApi(bool fireAndForget)
{
try
{
Expand All @@ -26,7 +26,14 @@ public void SendHarObjToReadMeApi()
string apiKey = "Basic " + Convert.ToBase64String(Encoding.UTF8.GetBytes(this.apiKey + ":"));
request.AddHeader("Authorization", apiKey);
request.AddParameter("application/json", this.harJsonObject, ParameterType.RequestBody);
client.ExecuteAsync(request);
if (fireAndForget)
{
client.ExecuteAsync(request);
}
else
{
client.Execute(request);
}
}
catch (Exception)
{
Expand Down
7 changes: 6 additions & 1 deletion packages/dotnet/ReadMe/Metrics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public async Task InvokeAsync(HttpContext context)

string harJsonObj = await harJsonBuilder.BuildHar();
ReadMeApiCaller readmeApiCaller = new ReadMeApiCaller(harJsonObj, configValues.apiKey);
readmeApiCaller.SendHarObjToReadMeApi();
readmeApiCaller.SendHarObjToReadMeApi(configValues.options.fireAndForget);
}
else
{
Expand Down Expand Up @@ -114,6 +114,11 @@ private ConfigValues GetConfigValues()
optionsObj.baseLogUrl = options.GetSection("baseLogUrl").Value;
}

if (options.GetSection("fireAndForget").Value != null)
{
optionsObj.fireAndForget = bool.Parse(options.GetSection("fireAndForget").Value);
}

configValues.options = optionsObj;
return configValues;
}
Expand Down

0 comments on commit 959fe8a

Please sign in to comment.