@@ -75,8 +75,7 @@ class RealPirJobsRunner @Inject constructor(
75
75
val startTimeInMillis = currentTimeProvider.currentTimeMillis()
76
76
emitStartPixel(executionType)
77
77
78
- // This should be all brokers since all brokers have scan steps and inactive brokers are removed
79
- val activeBrokers = pirRepository.getAllBrokersForScan().toHashSet()
78
+ val activeBrokers = pirRepository.getAllActiveBrokers().toHashSet()
80
79
81
80
// Multiple profile support
82
81
val profileQueries = obtainProfiles()
@@ -88,6 +87,7 @@ class RealPirJobsRunner @Inject constructor(
88
87
emitCompletedPixel(executionType, startTimeInMillis)
89
88
return @withContext Result .success(Unit )
90
89
}
90
+
91
91
if (activeBrokers.isEmpty()) {
92
92
logcat { " PIR-JOB-RUNNER: No active brokers available. Completing run." }
93
93
pixelSender.reportScanStats(0 )
@@ -98,8 +98,19 @@ class RealPirJobsRunner @Inject constructor(
98
98
99
99
attemptCreateScanJobs(activeBrokers, profileQueries)
100
100
executeScanJobs(context, executionType, activeBrokers)
101
- attemptCreateOptOutJobs(activeBrokers)
102
- executeOptOutJobs(context)
101
+
102
+ val formOptOutBrokers = pirRepository.getBrokersForOptOut(true ).toSet()
103
+ val activeFormOptOutBrokers = formOptOutBrokers.intersect(activeBrokers)
104
+
105
+ if (activeFormOptOutBrokers.isEmpty()) {
106
+ logcat { " PIR-JOB-RUNNER: No active parent brokers available for optout. Completing run." }
107
+ pixelSender.reportOptOutStats(0 )
108
+ emitCompletedPixel(executionType, startTimeInMillis)
109
+ return @withContext Result .success(Unit )
110
+ }
111
+
112
+ attemptCreateOptOutJobs(activeFormOptOutBrokers)
113
+ executeOptOutJobs(context, activeFormOptOutBrokers)
103
114
104
115
logcat { " PIR-JOB-RUNNER: Completed." }
105
116
emitCompletedPixel(executionType, startTimeInMillis)
@@ -137,7 +148,7 @@ class RealPirJobsRunner @Inject constructor(
137
148
profileQueries : List <ProfileQuery >,
138
149
) {
139
150
logcat { " PIR-JOB-RUNNER: Attempting to create new scan jobs" }
140
- // No scan jobs mean that this is the first time PR is being run OR all jobs have been invalidated.
151
+ // No scan jobs mean that this is the first time PIR is being run OR all jobs have been invalidated.
141
152
val toCreate = mutableListOf<ScanJobRecord >()
142
153
143
154
profileQueries.filter {
@@ -187,12 +198,12 @@ class RealPirJobsRunner @Inject constructor(
187
198
}
188
199
}
189
200
190
- private suspend fun attemptCreateOptOutJobs (activeBrokers : Set <String >) {
201
+ private suspend fun attemptCreateOptOutJobs (activeFormOptOutBrokers : Set <String >) {
191
202
val toCreate = mutableListOf<OptOutJobRecord >()
192
203
val extractedProfiles = pirRepository.getAllExtractedProfiles()
193
204
194
205
extractedProfiles.forEach {
195
- if (activeBrokers .contains(it.brokerName) &&
206
+ if (activeFormOptOutBrokers .contains(it.brokerName) &&
196
207
pirSchedulingRepository.getValidOptOutJobRecord(it.dbId) == null
197
208
) {
198
209
toCreate.add(
@@ -213,12 +224,13 @@ class RealPirJobsRunner @Inject constructor(
213
224
}
214
225
}
215
226
216
- private suspend fun executeOptOutJobs (context : Context ) {
217
- val formOptOutBrokers = pirRepository.getBrokersForOptOut(true )
218
-
227
+ private suspend fun executeOptOutJobs (
228
+ context : Context ,
229
+ activeFormOptOutBrokers : Set <String >,
230
+ ) {
219
231
eligibleOptOutJobProvider.getAllEligibleOptOutJobs(currentTimeProvider.currentTimeMillis())
220
232
.filter {
221
- formOptOutBrokers .contains(it.brokerName)
233
+ activeFormOptOutBrokers .contains(it.brokerName)
222
234
}.also {
223
235
pixelSender.reportOptOutStats(it.size)
224
236
if (it.isNotEmpty()) {
0 commit comments