the-algorithm/graph-feature-service/src/main/scala/com/twitter/graph_feature_service/server/handlers/ServerWarmupHandler.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

46 lines
1.5 KiB
Scala

package com.twitter.graph_feature_service.server.handlers
import com.twitter.finatra.thrift.routing.ThriftWarmup
import com.twitter.graph_feature_service.thriftscala.EdgeType.FavoritedBy
import com.twitter.graph_feature_service.thriftscala.EdgeType.FollowedBy
import com.twitter.graph_feature_service.thriftscala.EdgeType.Following
import com.twitter.graph_feature_service.thriftscala.Server.GetIntersection
import com.twitter.graph_feature_service.thriftscala.FeatureType
import com.twitter.graph_feature_service.thriftscala.GfsIntersectionRequest
import com.twitter.inject.utils.Handler
import com.twitter.scrooge.Request
import com.twitter.util.logging.Logger
import javax.inject.Inject
import javax.inject.Singleton
import scala.util.Random
@Singleton
class ServerWarmupHandler @Inject() (warmup: ThriftWarmup) extends Handler {
val logger: Logger = Logger("WarmupHandler")
// TODO: Add the testing accounts to warm-up the service.
private val testingAccounts: Array[Long] = Seq.empty.toArray
private def getRandomRequest: GfsIntersectionRequest = {
GfsIntersectionRequest(
testingAccounts(Random.nextInt(testingAccounts.length)),
testingAccounts,
Seq(FeatureType(Following, FollowedBy), FeatureType(Following, FavoritedBy))
)
}
override def handle(): Unit = {
warmup.sendRequest(
GetIntersection,
Request(
GetIntersection.Args(
getRandomRequest
)),
10
)()
logger.info("Warmup Done!")
}
}