the-algorithm/pushservice/src/main/scala/com/twitter/frigate/pushservice/send_handler/generator/PushRequestToCandidate.scala
twitter-team b389c3d302 Open-sourcing pushservice
Pushservice is the main recommendation service we use to surface recommendations to our users via notifications. It fetches candidates from various sources, ranks them in order of relevance, and applies filters to determine the best one to send.
2023-05-19 16:27:07 -05:00

50 lines
2.0 KiB
Scala

package com.twitter.frigate.pushservice.send_handler.generator
import com.twitter.frigate.pushservice.model.PushTypes.RawCandidate
import com.twitter.frigate.pushservice.model.PushTypes.Target
import com.twitter.frigate.pushservice.config.Config
import com.twitter.frigate.pushservice.exception.UnsupportedCrtException
import com.twitter.frigate.thriftscala.FrigateNotification
import com.twitter.frigate.thriftscala.{CommonRecommendationType => CRT}
import com.twitter.util.Future
object PushRequestToCandidate {
final def generatePushCandidate(
frigateNotification: FrigateNotification,
target: Target
)(
implicit config: Config
): Future[RawCandidate] = {
val candidateGenerator: (Target, FrigateNotification) => Future[RawCandidate] = {
frigateNotification.commonRecommendationType match {
case CRT.MagicFanoutNewsEvent => MagicFanoutNewsEventCandidateGenerator.getCandidate
case CRT.ScheduledSpaceSubscriber => ScheduledSpaceSubscriberCandidateGenerator.getCandidate
case CRT.ScheduledSpaceSpeaker => ScheduledSpaceSpeakerCandidateGenerator.getCandidate
case CRT.MagicFanoutSportsEvent =>
MagicFanoutSportsEventCandidateGenerator.getCandidate(
_,
_,
config.basketballGameScoreStore,
config.baseballGameScoreStore,
config.cricketMatchScoreStore,
config.soccerMatchScoreStore,
config.nflGameScoreStore,
config.semanticCoreMegadataStore
)
case CRT.MagicFanoutProductLaunch =>
MagicFanoutProductLaunchCandidateGenerator.getCandidate
case CRT.NewCreator =>
MagicFanoutCreatorEventCandidateGenerator.getCandidate
case CRT.CreatorSubscriber =>
MagicFanoutCreatorEventCandidateGenerator.getCandidate
case _ =>
throw new UnsupportedCrtException(
"UnsupportedCrtException for SendHandler: " + frigateNotification.commonRecommendationType)
}
}
candidateGenerator(target, frigateNotification)
}
}