Truncate for queue as well + bug fix
@@ -4,6 +4,7 @@ using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
using ApiService.OneFuzzLib.Orm;
+using Azure;
using Microsoft.OneFuzz.Service.OneFuzzLib.Orm;
namespace Microsoft.OneFuzz.Service;
@@ -49,18 +50,31 @@ public class WebhookOperations : Orm<Webhook>, IWebhookOperations {
var r = await _context.WebhookMessageLogOperations.Replace(message);
if (!r.IsOk) {
if (r.ErrorV.Reason.Contains("The entity is larger than the maximum allowed size") && eventMessage.Event is ITruncatable<BaseEvent> truncatableEvent) {
- _logTracer.WithTags(tags).Warning($"The WebhookMessageLog was too long. Truncating event data and trying again.");
- var truncatedEventMessage = message with {
+ _logTracer.WithTags(tags).Warning($"The WebhookMessageLog was too long for Azure Table. Truncating event data and trying again.");
+ message = message with {
Event = truncatableEvent.Truncate(1000)
};
- r = await _context.WebhookMessageLogOperations.Replace(truncatedEventMessage);
+ r = await _context.WebhookMessageLogOperations.Replace(message);
}
if (!r.IsOk) {
_logTracer.WithHttpStatus(r.ErrorV).WithTags(tags).Error($"Failed to replace webhook message log {webhook.WebhookId:Tag:WebhookId} - {eventMessage.EventId:Tag:EventId}");
}
}
+ try {
+ await _context.WebhookMessageLogOperations.QueueWebhook(message);
+ } catch (RequestFailedException ex) {
+ if (ex.Message.Contains("The request body is too large") && eventMessage.Event is ITruncatable<BaseEvent> truncatableEvent) {
+ _logTracer.WithTags(tags).Warning($"The WebhookMessageLog was too long for Azure Queue. Truncating event data and trying again.");
+ message = message with {
+ Event = truncatableEvent.Truncate(1000)
+ };
await _context.WebhookMessageLogOperations.QueueWebhook(message);
+ } else {
+ // Not handled
+ throw ex;
+ }
+ }
}
public async Async.Task<bool> Send(WebhookMessageLog messageLog) {
