|
4 | 4 | using System.Text.Json; |
5 | 5 | using System.Threading.Tasks; |
6 | 6 | using ApiService.OneFuzzLib.Orm; |
| 7 | +using Azure; |
7 | 8 | using Microsoft.OneFuzz.Service.OneFuzzLib.Orm; |
8 | 9 |
|
9 | 10 | namespace Microsoft.OneFuzz.Service; |
@@ -49,18 +50,31 @@ async private Async.Task AddEvent(Webhook webhook, EventMessage eventMessage) { |
49 | 50 | var r = await _context.WebhookMessageLogOperations.Replace(message); |
50 | 51 | if (!r.IsOk) { |
51 | 52 | if (r.ErrorV.Reason.Contains("The entity is larger than the maximum allowed size") && eventMessage.Event is ITruncatable<BaseEvent> truncatableEvent) { |
52 | | - _logTracer.WithTags(tags).Warning($"The WebhookMessageLog was too long. Truncating event data and trying again."); |
53 | | - var truncatedEventMessage = message with { |
| 53 | + _logTracer.WithTags(tags).Warning($"The WebhookMessageLog was too long for Azure Table. Truncating event data and trying again."); |
| 54 | + message = message with { |
54 | 55 | Event = truncatableEvent.Truncate(1000) |
55 | 56 | }; |
56 | | - r = await _context.WebhookMessageLogOperations.Replace(truncatedEventMessage); |
| 57 | + r = await _context.WebhookMessageLogOperations.Replace(message); |
57 | 58 | } |
58 | 59 | if (!r.IsOk) { |
59 | 60 | _logTracer.WithHttpStatus(r.ErrorV).WithTags(tags).Error($"Failed to replace webhook message log {webhook.WebhookId:Tag:WebhookId} - {eventMessage.EventId:Tag:EventId}"); |
60 | 61 | } |
61 | 62 | } |
62 | 63 |
|
63 | | - await _context.WebhookMessageLogOperations.QueueWebhook(message); |
| 64 | + try { |
| 65 | + await _context.WebhookMessageLogOperations.QueueWebhook(message); |
| 66 | + } catch (RequestFailedException ex) { |
| 67 | + if (ex.Message.Contains("The request body is too large") && eventMessage.Event is ITruncatable<BaseEvent> truncatableEvent) { |
| 68 | + _logTracer.WithTags(tags).Warning($"The WebhookMessageLog was too long for Azure Queue. Truncating event data and trying again."); |
| 69 | + message = message with { |
| 70 | + Event = truncatableEvent.Truncate(1000) |
| 71 | + }; |
| 72 | + await _context.WebhookMessageLogOperations.QueueWebhook(message); |
| 73 | + } else { |
| 74 | + // Not handled |
| 75 | + throw ex; |
| 76 | + } |
| 77 | + } |
64 | 78 | } |
65 | 79 |
|
66 | 80 | public async Async.Task<bool> Send(WebhookMessageLog messageLog) { |
|
0 commit comments