Skip to content

Commit

Permalink
Use utils.Timer for logging
Browse files Browse the repository at this point in the history
  • Loading branch information
simonbyford committed Oct 31, 2023
1 parent 5b1d406 commit ed3d9bb
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 9 deletions.
6 changes: 4 additions & 2 deletions apps/checker/app/matchers/DictionaryMatcher.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import org.languagetool.{JLanguageTool, Language, ResultCache, UserConfig}
import play.api.Logging
import services.collins.{CollinsEnglish, MorfologikCollinsSpellerRule, SpellDictionaryBuilder}
import services.{EntityHelper, EntityInText, MatcherRequest}
import utils.Matcher
import utils.{Matcher, Timer}

import scala.concurrent.{ExecutionContext, Future}
import scala.jdk.CollectionConverters.ListHasAsScala
Expand Down Expand Up @@ -68,8 +68,10 @@ class DictionaryMatcher(
)(implicit ec: ExecutionContext): Future[List[RuleMatch]] = {
// There is only ever one block
val block = request.blocks.head
val eventualNamedEntities =

val eventualNamedEntities = Timer.timeAsync(taskName = "getEntityResultFromNERService") {
entityHelper.getEntityResultFromNERService(text = block.text, offset = block.from)
}

for {
namedEntities <- eventualNamedEntities
Expand Down
7 changes: 0 additions & 7 deletions apps/checker/app/services/EntityHelper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ class EntityHelper(wsClient: WSClient, config: CheckerConfig) {
s"{\"articles\": [{\"text\": ${Json.toJson(text)}}],\"model\": \"$model\",\"entities\": ${Json
.toJson(entityTypes)}}"

val before = System.currentTimeMillis

wsClient
.url(url)
.withHttpHeaders(
Expand All @@ -44,11 +42,8 @@ class EntityHelper(wsClient: WSClient, config: CheckerConfig) {
)
.post(body)
.map { response =>
val after = System.currentTimeMillis
response.status match {
case 200 => {
logger.info(s"Request to ${config.nerApiUrl} succeeded in ${after - before}ms")

val entitiesJson = response.json.result("result")(0)("ents")
entitiesJson.validate[List[NERResult]] match {
case JsSuccess(value, _) =>
Expand All @@ -68,8 +63,6 @@ class EntityHelper(wsClient: WSClient, config: CheckerConfig) {
}
}
case _ => {
logger.info(s"Request to ${config.nerApiUrl} failed in ${after - before}ms")

Left(new Error(s"${response.status} ${response.statusText}"))
}
}
Expand Down

0 comments on commit ed3d9bb

Please sign in to comment.