5
5
namespace Microsoft . OneFuzz . Service ;
6
6
7
7
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 ) ;
9
9
IAsyncEnumerable < Notification > GetNotifications ( Container container ) ;
10
10
IAsyncEnumerable < ( Task , IEnumerable < Container > ) > GetQueueTasks ( ) ;
11
11
Async . Task < OneFuzzResult < Notification > > Create ( Container container , NotificationTemplate config , bool replaceExisting ) ;
@@ -21,24 +21,29 @@ public NotificationOperations(ILogger<NotificationOperations> log, IOnefuzzConte
21
21
: base ( log , context ) {
22
22
23
23
}
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
+
25
27
// We don't want to store file added events for the events container because that causes an infinite loop
26
28
if ( container == WellKnownContainers . Events ) {
27
- return ;
29
+ return result ;
28
30
}
29
31
30
32
var notifications = GetNotifications ( container ) ;
31
33
var hasNotifications = await notifications . AnyAsync ( ) ;
32
34
var reportOrRegression = await _context . Reports . GetReportOrRegression ( container , filename , expectReports : hasNotifications ) ;
33
- if ( hasNotifications && await _context . FeatureManagerSnapshot . IsEnabledAsync ( FeatureFlagConstants . EnableWorkItemCreation ) ) {
35
+ if ( hasNotifications ) {
34
36
var done = new List < NotificationTemplate > ( ) ;
35
37
await foreach ( var notification in notifications ) {
36
38
if ( done . Contains ( notification . Config ) ) {
37
39
continue ;
38
40
}
39
41
40
42
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
+ }
42
47
}
43
48
}
44
49
@@ -77,6 +82,8 @@ public async Async.Task NewFiles(Container container, string filename, bool isLa
77
82
} else {
78
83
await _context . Events . SendEvent ( new EventFileAdded ( container , filename ) ) ;
79
84
}
85
+
86
+ return result ;
80
87
}
81
88
82
89
public async System . Threading . Tasks . Task < OneFuzzResultVoid > TriggerNotification ( Container container ,
@@ -87,8 +94,12 @@ await _context.Teams.NotifyTeams(teamsTemplate, container, reportOrRegression!,
87
94
notification . NotificationId ) ;
88
95
break ;
89
96
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
+ }
92
103
case GithubIssuesTemplate githubIssuesTemplate when reportOrRegression is not null :
93
104
await _context . GithubIssues . GithubIssue ( githubIssuesTemplate , container , reportOrRegression ,
94
105
notification . NotificationId ) ;
0 commit comments