add compile & test worker
This commit is contained in:
39
src/LiquidCode.Tester.Worker/Services/CallbackService.cs
Normal file
39
src/LiquidCode.Tester.Worker/Services/CallbackService.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using LiquidCode.Tester.Common.Models;
|
||||
|
||||
namespace LiquidCode.Tester.Worker.Services;
|
||||
|
||||
public class CallbackService : ICallbackService
|
||||
{
|
||||
private readonly IHttpClientFactory _httpClientFactory;
|
||||
private readonly ILogger<CallbackService> _logger;
|
||||
|
||||
public CallbackService(IHttpClientFactory httpClientFactory, ILogger<CallbackService> logger)
|
||||
{
|
||||
_httpClientFactory = httpClientFactory;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public async Task SendStatusAsync(string callbackUrl, TesterResponseModel response)
|
||||
{
|
||||
_logger.LogInformation("Sending status update to {CallbackUrl} for submit {SubmitId}", callbackUrl, response.SubmitId);
|
||||
|
||||
try
|
||||
{
|
||||
var httpClient = _httpClientFactory.CreateClient();
|
||||
var json = JsonSerializer.Serialize(response);
|
||||
var content = new StringContent(json, Encoding.UTF8, "application/json");
|
||||
|
||||
var httpResponse = await httpClient.PostAsync(callbackUrl, content);
|
||||
httpResponse.EnsureSuccessStatusCode();
|
||||
|
||||
_logger.LogInformation("Status update sent successfully");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Failed to send status update to {CallbackUrl}", callbackUrl);
|
||||
// Don't throw - callback failures shouldn't stop testing
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user