Skip to content

Commit

Permalink
Only run task on visible projects and add some more sentry stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
Ewoutvans authored and felixoi committed Oct 8, 2018
1 parent 1a179bc commit 8ca7f35
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 7 deletions.
2 changes: 1 addition & 1 deletion app/controllers/Application.scala
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ final class Application @Inject()(forms: OreForms)(
implicit request =>
val projectTable = TableQuery[ProjectTableMain]
val query = for {
noTopicProject <- projectTable if noTopicProject.topicId.?.isEmpty || noTopicProject.postId.?.isEmpty
noTopicProject <- projectTable if noTopicProject.topicId.isEmpty || noTopicProject.postId.?.isEmpty
dirtyTopicProject <- projectTable if dirtyTopicProject.isTopicDirty
staleProject <- projectTable
if staleProject.lastUpdated > new Timestamp(new Date().getTime - this.config.projects.get[Int]("staleAge"))
Expand Down
4 changes: 2 additions & 2 deletions app/db/impl/schema/tableSchema.scala
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ trait ProjectTable
def category = column[Category]("category")
def stars = column[Long]("stars")
def views = column[Long]("views")
def topicId = column[Int]("topic_id")
def topicId = column[Option[Int]]("topic_id")
def postId = column[Int]("post_id")
def isTopicDirty = column[Boolean]("is_topic_dirty")
def lastUpdated = column[Timestamp]("last_updated")
Expand All @@ -78,7 +78,7 @@ trait ProjectTable
stars,
views,
downloads,
topicId.?,
topicId,
postId.?,
isTopicDirty,
visibility,
Expand Down
15 changes: 14 additions & 1 deletion app/discourse/OreDiscourseApi.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ import util.StringUtils._
import akka.actor.Scheduler
import cats.instances.future._
import cats.syntax.all._
import com.fasterxml.jackson.core.JsonParseException
import com.google.common.base.Preconditions.checkArgument
import org.slf4j.MDC
import org.spongepowered.play.discourse.DiscourseApi

/**
Expand Down Expand Up @@ -199,7 +201,18 @@ trait OreDiscourseApi extends DiscourseApi {
}
case Failure(e) =>
// Discourse never received our request!
fail(e.getMessage)
MDC.put("username", ownerName)
MDC.put("topicId", topicId.get.toString)
MDC.put("title", title)
e match {
case runtimeException: RuntimeException => {
if (runtimeException.getCause.isInstanceOf[JsonParseException]) {
MDC.put("jsonException", runtimeException.getCause.getMessage)
}
fail(e.getMessage)
}
case _ => fail(e.getMessage)
}
}

resultPromise.future
Expand Down
10 changes: 7 additions & 3 deletions app/discourse/RecoveryTask.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ import scala.concurrent.duration.FiniteDuration

import play.api.Logger

import db.ModelService
import db.{ModelFilter, ModelService}
import db.impl.OrePostgresDriver.api._
import db.impl.access.ProjectBase
import ore.OreConfig

import akka.actor.Scheduler
import models.project.{Project, Visibility}

/**
* Task to periodically retry failed Discourse requests.
Expand All @@ -36,12 +37,15 @@ class RecoveryTask(scheduler: Scheduler, retryRate: FiniteDuration, api: OreDisc
override def run(): Unit = {
Logger.debug("Running Discourse recovery task...")

this.projects.filter(_.topicId === -1).foreach { toCreate =>
val topicFilter: ModelFilter[Project] = ModelFilter[Project](_.topicId.isEmpty)
val dirtyFilter: ModelFilter[Project] = ModelFilter[Project](_.isTopicDirty)

this.projects.filter((topicFilter +&& Visibility.isPublicFilter).fn).foreach { toCreate =>
Logger.debug(s"Creating ${toCreate.size} topics...")
toCreate.foreach(this.api.createProjectTopic)
}

this.projects.filter(_.isTopicDirty).foreach { toUpdate =>
this.projects.filter((dirtyFilter +&& Visibility.isPublicFilter).fn).foreach { toUpdate =>
Logger.debug(s"Updating ${toUpdate.size} topics...")
toUpdate.foreach(this.api.updateProjectTopic)
}
Expand Down
1 change: 1 addition & 0 deletions conf/sentry.properties
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
stacktrace.app.packages=
maxmessagelength=10000

0 comments on commit 8ca7f35

Please sign in to comment.