the-algorithm/product-mixer/component-library/src/main/scala/com/twitter/product_mixer/component_library/gate/NoCandidatesGate.scala
twitter-team ef4c5eb65e Twitter Recommendation Algorithm
Please note we have force-pushed a new initial commit in order to remove some publicly-available Twitter user information. Note that this process may be required in the future.
2023-03-31 17:36:31 -05:00

22 lines
1.1 KiB
Scala

package com.twitter.product_mixer.component_library.gate
import com.twitter.product_mixer.core.functional_component.common.CandidateScope
import com.twitter.product_mixer.core.functional_component.gate.QueryAndCandidateGate
import com.twitter.product_mixer.core.model.common.identifier.GateIdentifier
import com.twitter.product_mixer.core.model.common.presentation.CandidateWithDetails
import com.twitter.product_mixer.core.pipeline.PipelineQuery
import com.twitter.stitch.Stitch
/**
* A Gate that only continues if the previously returned candidates are empty. This is useful
* for gating dependent candidate pipelines that are intedned to be used as a backfill when there
* are no candidates available.
*/
case class NoCandidatesGate(scope: CandidateScope) extends QueryAndCandidateGate[PipelineQuery] {
override val identifier: GateIdentifier = GateIdentifier("NoCandidates")
override def shouldContinue(
query: PipelineQuery,
candidates: Seq[CandidateWithDetails]
): Stitch[Boolean] = Stitch.value(scope.partition(candidates).candidatesInScope.isEmpty)
}