@@ -51,29 +51,55 @@ class RealOptOutConfirmationReporter @Inject constructor(
5151
5252 if (activeBrokers.isEmpty() || allValidRequestedOptOutJobs.isEmpty()) return @withContext
5353
54- attemptFire7dayPixel(allValidRequestedOptOutJobs, activeBrokers)
54+ allValidRequestedOptOutJobs.also {
55+ it.attemptFirePixelForConfirmationDay(
56+ activeBrokers,
57+ 7 ,
58+ { jobRecord -> jobRecord.confirmation7dayReportSentDateMs == 0L },
59+ { brokerUrl -> pixelSender.reportBrokerOptOutConfirmed7Days(brokerUrl) },
60+ { brokerUrl -> pixelSender.reportBrokerOptOutUnconfirmed7Days(brokerUrl) },
61+ { jobRecord, now ->
62+ pirSchedulingRepository.markOptOutDay7ConfirmationPixelSent(jobRecord.extractedProfileId, now)
63+ },
64+ )
65+
66+ it.attemptFirePixelForConfirmationDay(
67+ activeBrokers,
68+ 14 ,
69+ { jobRecord -> jobRecord.confirmation14dayReportSentDateMs == 0L },
70+ { brokerUrl -> pixelSender.reportBrokerOptOutConfirmed14Days(brokerUrl) },
71+ { brokerUrl -> pixelSender.reportBrokerOptOutUnconfirmed14Days(brokerUrl) },
72+ { jobRecord, now ->
73+ pirSchedulingRepository.markOptOutDay14ConfirmationPixelSent(jobRecord.extractedProfileId, now)
74+ },
75+ )
76+ }
5577 }
5678 }
5779
58- private suspend fun attemptFire7dayPixel (
59- allValidRequestedOptOutJobs : List <OptOutJobRecord >,
80+ private suspend fun List<OptOutJobRecord>.attemptFirePixelForConfirmationDay (
6081 activeBrokers : Map <String , Broker >,
82+ confirmationDay : Long ,
83+ jobRecordFilter : (OptOutJobRecord ) -> Boolean ,
84+ emitConfirmPixel : (String ) -> Unit ,
85+ emitUnconfirmPixel : (String ) -> Unit ,
86+ markOptOutJobRecordReporting : suspend (OptOutJobRecord , Long ) -> Unit ,
6187 ) {
6288 val now = currentTimeProvider.currentTimeMillis()
63- val optOutsForSevenDayPixel = allValidRequestedOptOutJobs .filter {
64- it.daysPassedSinceSubmission(now, 7 ) && it.confirmation7dayReportSentDateMs == 0L
89+ val optOutsForSevenDayPixel = this .filter {
90+ it.daysPassedSinceSubmission(now, confirmationDay ) && jobRecordFilter(it)
6591 }
6692
6793 optOutsForSevenDayPixel.forEach { optOutJobRecord ->
6894 val brokerUrl = activeBrokers[optOutJobRecord.brokerName]?.url ? : return @forEach
6995
7096 if (optOutJobRecord.status == REMOVED ) {
71- pixelSender.reportBrokerOptOutConfirmed7Days (brokerUrl)
97+ emitConfirmPixel (brokerUrl)
7298 } else {
73- pixelSender.reportBrokerOptOutUnconfirmed7Days (brokerUrl)
99+ emitUnconfirmPixel (brokerUrl)
74100 }
75101
76- pirSchedulingRepository.markOptOutDay7ConfirmationPixelSent (optOutJobRecord.extractedProfileId , now)
102+ markOptOutJobRecordReporting (optOutJobRecord, now)
77103 }
78104 }
79105
0 commit comments