Skip to content
This repository was archived by the owner on Nov 1, 2023. It is now read-only.

Commit 638ff8c

Browse files
tevoineaAdamL-Microsoft
authored andcommitted
Requeue ado notification on ff (#3358)
* Requeue ado notification on ff * Fix test
1 parent 9f8a8a0 commit 638ff8c

File tree

4 files changed

+28
-13
lines changed

4 files changed

+28
-13
lines changed

src/ApiService/ApiService/Functions/QueueFileChanges.cs

+8-5
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,17 @@ public async Async.Task Run(
6161
// requeuing ourselves because azure functions doesn't support retry policies
6262
// for queue based functions.
6363

64-
await FileAdded(fileChangeEvent, isLastRetryAttempt: false);
64+
var result = await FileAdded(fileChangeEvent, isLastRetryAttempt: false);
65+
if (!result.IsOk && result.ErrorV.Code == ErrorCode.ADO_WORKITEM_PROCESSING_DISABLED) {
66+
await RequeueMessage(msg, TimeSpan.FromDays(1));
67+
}
6568
} catch (Exception e) {
6669
_log.LogError(e, "File Added failed");
6770
await RequeueMessage(msg);
6871
}
6972
}
7073

71-
private async Async.Task FileAdded(JsonDocument fileChangeEvent, bool isLastRetryAttempt) {
74+
private async Async.Task<OneFuzzResultVoid> FileAdded(JsonDocument fileChangeEvent, bool isLastRetryAttempt) {
7275
var data = fileChangeEvent.RootElement.GetProperty("data");
7376
var url = data.GetProperty("url").GetString()!;
7477
var parts = url.Split("/").Skip(3).ToList();
@@ -77,10 +80,10 @@ private async Async.Task FileAdded(JsonDocument fileChangeEvent, bool isLastRetr
7780
var path = string.Join('/', parts.Skip(1));
7881

7982
_log.LogInformation("file added : {Container} - {Path}", container, path);
80-
await _notificationOperations.NewFiles(Container.Parse(container), path, isLastRetryAttempt);
83+
return await _notificationOperations.NewFiles(Container.Parse(container), path, isLastRetryAttempt);
8184
}
8285

83-
private async Async.Task RequeueMessage(string msg) {
86+
private async Async.Task RequeueMessage(string msg, TimeSpan? visibilityTimeout = null) {
8487
var json = JsonNode.Parse(msg);
8588

8689
// Messages that are 'manually' requeued by us as opposed to being requeued by the azure functions runtime
@@ -103,7 +106,7 @@ await _context.Queue.QueueObject(
103106
queueName,
104107
json,
105108
StorageType.Config,
106-
CalculateExponentialBackoff(newCustomDequeueCount))
109+
visibilityTimeout ?? CalculateExponentialBackoff(newCustomDequeueCount))
107110
.IgnoreResult();
108111
}
109112

src/ApiService/ApiService/OneFuzzTypes/Enums.cs

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ public enum ErrorCode {
4747
ADO_VALIDATION_UNEXPECTED_HTTP_EXCEPTION = 490,
4848
ADO_VALIDATION_UNEXPECTED_ERROR = 491,
4949
ADO_VALIDATION_MISSING_PAT_SCOPES = 492,
50+
ADO_WORKITEM_PROCESSING_DISABLED = 494,
5051
// NB: if you update this enum, also update enums.py
5152
}
5253

src/ApiService/ApiService/TestHooks/NotificationOperationsTestHooks.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public async Task<HttpResponseData> NewFiles([HttpTrigger(AuthorizationLevel.Ano
3131
var fileName = query["fileName"];
3232
var isLastRetryAttempt = UriExtension.GetBool("isLastRetryAttempt", query, true);
3333

34-
await _notificationOps.NewFiles(Container.Parse(container), fileName, isLastRetryAttempt);
34+
_ = await _notificationOps.NewFiles(Container.Parse(container), fileName, isLastRetryAttempt);
3535
var resp = req.CreateResponse(HttpStatusCode.OK);
3636
return resp;
3737
}

src/ApiService/ApiService/onefuzzlib/NotificationOperations.cs

+18-7
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
namespace Microsoft.OneFuzz.Service;
66

77
public interface INotificationOperations : IOrm<Notification> {
8-
Async.Task NewFiles(Container container, string filename, bool isLastRetryAttempt);
8+
Async.Task<OneFuzzResultVoid> NewFiles(Container container, string filename, bool isLastRetryAttempt);
99
IAsyncEnumerable<Notification> GetNotifications(Container container);
1010
IAsyncEnumerable<(Task, IEnumerable<Container>)> GetQueueTasks();
1111
Async.Task<OneFuzzResult<Notification>> Create(Container container, NotificationTemplate config, bool replaceExisting);
@@ -21,24 +21,29 @@ public NotificationOperations(ILogger<NotificationOperations> log, IOnefuzzConte
2121
: base(log, context) {
2222

2323
}
24-
public async Async.Task NewFiles(Container container, string filename, bool isLastRetryAttempt) {
24+
public async Async.Task<OneFuzzResultVoid> NewFiles(Container container, string filename, bool isLastRetryAttempt) {
25+
var result = OneFuzzResultVoid.Ok;
26+
2527
// We don't want to store file added events for the events container because that causes an infinite loop
2628
if (container == WellKnownContainers.Events) {
27-
return;
29+
return result;
2830
}
2931

3032
var notifications = GetNotifications(container);
3133
var hasNotifications = await notifications.AnyAsync();
3234
var reportOrRegression = await _context.Reports.GetReportOrRegression(container, filename, expectReports: hasNotifications);
33-
if (hasNotifications && await _context.FeatureManagerSnapshot.IsEnabledAsync(FeatureFlagConstants.EnableWorkItemCreation)) {
35+
if (hasNotifications) {
3436
var done = new List<NotificationTemplate>();
3537
await foreach (var notification in notifications) {
3638
if (done.Contains(notification.Config)) {
3739
continue;
3840
}
3941

4042
done.Add(notification.Config);
41-
_ = await TriggerNotification(container, notification, reportOrRegression, isLastRetryAttempt);
43+
var notificationResult = await TriggerNotification(container, notification, reportOrRegression, isLastRetryAttempt);
44+
if (result.IsOk && !notificationResult.IsOk) {
45+
result = notificationResult;
46+
}
4247
}
4348
}
4449

@@ -77,6 +82,8 @@ public async Async.Task NewFiles(Container container, string filename, bool isLa
7782
} else {
7883
await _context.Events.SendEvent(new EventFileAdded(container, filename));
7984
}
85+
86+
return result;
8087
}
8188

8289
public async System.Threading.Tasks.Task<OneFuzzResultVoid> TriggerNotification(Container container,
@@ -87,8 +94,12 @@ await _context.Teams.NotifyTeams(teamsTemplate, container, reportOrRegression!,
8794
notification.NotificationId);
8895
break;
8996
case AdoTemplate adoTemplate when reportOrRegression is not null:
90-
return await _context.Ado.NotifyAdo(adoTemplate, container, reportOrRegression, isLastRetryAttempt,
91-
notification.NotificationId);
97+
if (await _context.FeatureManagerSnapshot.IsEnabledAsync(FeatureFlagConstants.EnableWorkItemCreation)) {
98+
return await _context.Ado.NotifyAdo(adoTemplate, container, reportOrRegression, isLastRetryAttempt,
99+
notification.NotificationId);
100+
} else {
101+
return OneFuzzResultVoid.Error(ErrorCode.ADO_WORKITEM_PROCESSING_DISABLED, "Work item processing is currently disabled");
102+
}
92103
case GithubIssuesTemplate githubIssuesTemplate when reportOrRegression is not null:
93104
await _context.GithubIssues.GithubIssue(githubIssuesTemplate, container, reportOrRegression,
94105
notification.NotificationId);

0 commit comments

Comments
 (0)