diff --git a/app/controllers/Application.scala b/app/controllers/Application.scala index ab48cf5b6..a4bdb491a 100644 --- a/app/controllers/Application.scala +++ b/app/controllers/Application.scala @@ -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")) diff --git a/app/db/impl/schema/tableSchema.scala b/app/db/impl/schema/tableSchema.scala index a206e0094..087a3b918 100644 --- a/app/db/impl/schema/tableSchema.scala +++ b/app/db/impl/schema/tableSchema.scala @@ -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") @@ -78,7 +78,7 @@ trait ProjectTable stars, views, downloads, - topicId.?, + topicId, postId.?, isTopicDirty, visibility, diff --git a/app/discourse/OreDiscourseApi.scala b/app/discourse/OreDiscourseApi.scala index 32b149c2f..e15af1eb8 100644 --- a/app/discourse/OreDiscourseApi.scala +++ b/app/discourse/OreDiscourseApi.scala @@ -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 /** @@ -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 diff --git a/app/discourse/RecoveryTask.scala b/app/discourse/RecoveryTask.scala index cef5ba2f9..d4b7086e6 100644 --- a/app/discourse/RecoveryTask.scala +++ b/app/discourse/RecoveryTask.scala @@ -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. @@ -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) } diff --git a/conf/sentry.properties b/conf/sentry.properties index edb10d222..65953541d 100644 --- a/conf/sentry.properties +++ b/conf/sentry.properties @@ -1 +1,2 @@ stacktrace.app.packages= +maxmessagelength=10000