mirror of
https://github.com/twitter/the-algorithm.git
synced 2024-12-22 18:21:51 +01:00
Update ObservedRequests.scala
Added comments for better readbility.
This commit is contained in:
parent
ec83d01dca
commit
9f3b990df8
@ -2,13 +2,26 @@ package com.twitter.timelineranker.observe
|
|||||||
|
|
||||||
import com.twitter.timelines.authorization.ReadRequest
|
import com.twitter.timelines.authorization.ReadRequest
|
||||||
import com.twitter.timelines.model.UserId
|
import com.twitter.timelines.model.UserId
|
||||||
import com.twitter.timelines.observe.ObservedAndValidatedRequests
|
import com.twitter.timelines.observe.{ObservedAndValidatedRequests, ServiceObserver, ServiceTracer}
|
||||||
import com.twitter.timelines.observe.ServiceObserver
|
|
||||||
import com.twitter.timelines.observe.ServiceTracer
|
|
||||||
import com.twitter.util.Future
|
import com.twitter.util.Future
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A trait that provides methods to observe and validate requests.
|
||||||
|
*/
|
||||||
trait ObservedRequests extends ObservedAndValidatedRequests {
|
trait ObservedRequests extends ObservedAndValidatedRequests {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Observe and validate a request.
|
||||||
|
*
|
||||||
|
* @param request the request to be observed and validated
|
||||||
|
* @param viewerIds the IDs of the viewers who can access the request
|
||||||
|
* @param stats the statistics to track for the request
|
||||||
|
* @param exceptionHandler a partial function to handle exceptions thrown during validation or observation
|
||||||
|
* @param f a function that takes a request and returns a future of the response
|
||||||
|
* @tparam R the type of the response
|
||||||
|
* @tparam Q the type of the request
|
||||||
|
* @return a future of the response
|
||||||
|
*/
|
||||||
def observeAndValidate[R, Q](
|
def observeAndValidate[R, Q](
|
||||||
request: Q,
|
request: Q,
|
||||||
viewerIds: Seq[UserId],
|
viewerIds: Seq[UserId],
|
||||||
@ -17,17 +30,23 @@ trait ObservedRequests extends ObservedAndValidatedRequests {
|
|||||||
)(
|
)(
|
||||||
f: Q => Future[R]
|
f: Q => Future[R]
|
||||||
): Future[R] = {
|
): Future[R] = {
|
||||||
super.observeAndValidate[Q, R](
|
super.observeAndValidate(
|
||||||
request,
|
request = request,
|
||||||
viewerIds,
|
viewerIds = viewerIds,
|
||||||
ReadRequest,
|
accessLevel = ReadRequest,
|
||||||
validateRequest,
|
validator = validateRequest[Q],
|
||||||
exceptionHandler,
|
errorHandler = exceptionHandler,
|
||||||
stats,
|
stats = stats,
|
||||||
ServiceTracer.identity[Q]
|
tracer = ServiceTracer.identity[Q]
|
||||||
)(f)
|
)(f)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validate a request.
|
||||||
|
*
|
||||||
|
* @param request the request to be validated
|
||||||
|
* @tparam Q the type of the request
|
||||||
|
*/
|
||||||
def validateRequest[Q](request: Q): Unit = {
|
def validateRequest[Q](request: Q): Unit = {
|
||||||
// TimelineQuery and its derived classes do not permit invalid instances to be constructed.
|
// TimelineQuery and its derived classes do not permit invalid instances to be constructed.
|
||||||
// Therefore no additional validation is required.
|
// Therefore no additional validation is required.
|
||||||
|
Loading…
Reference in New Issue
Block a user