Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
mbryzek committed Jun 6, 2024
1 parent 3961338 commit 5bc2774
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -1,25 +1,30 @@
package invariants
package processor

import anorm.SqlParser
import cats.data.ValidatedNec
import cats.implicits._
import invariants.{Invariant, Invariants}
import io.apibuilder.task.v0.models._
import play.api.db.Database

import javax.inject.Inject

/** Sync all invoices with a balance
*/
class CheckInvariants @Inject() (

class CheckInvariantsProcessor @Inject()(
args: TaskProcessorArgs,
invariants: Invariants,
database: Database,
) {
) extends TaskProcessor(args, TaskType.CheckInvariants) {

def process(): Unit = {
override def processRecord(id: String): ValidatedNec[String, Unit] = {
val results = invariants.all.map { i =>
val count = database.withConnection { c =>
i.query.as(SqlParser.long(1).*)(c).headOption.getOrElse(0L)
}
InvariantResult(i, count)
}
sendResults(results)
().validNec
}

private[this] case class InvariantResult(invariant: Invariant, count: Long)
Expand All @@ -41,4 +46,4 @@ class CheckInvariants @Inject() (
}
}
}
}
}
4 changes: 3 additions & 1 deletion api/app/processor/TaskActorCompanion.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ class TaskActorCompanion @Inject() (
userCreated: UserCreatedProcessor,
scheduleSyncGeneratorServices: ScheduleSyncGeneratorServicesProcessor,
syncGeneratorService: SyncGeneratorServiceProcessor,
email: EmailProcessor
email: EmailProcessor,
checkInvariants: CheckInvariantsProcessor,
) {

def process(typ: TaskType): Unit = {
Expand All @@ -23,6 +24,7 @@ class TaskActorCompanion @Inject() (
private[this] def lookup(typ: TaskType): BaseTaskProcessor = {
import TaskType._
typ match {
case CheckInvariants => checkInvariants
case IndexApplication => indexApplication
case CleanupDeletions => cleanupDeletions
case DiffVersion => diffVersion
Expand Down
13 changes: 0 additions & 13 deletions api/test/invariants/CheckInvariantsSpec.scala

This file was deleted.

13 changes: 13 additions & 0 deletions api/test/processor/CheckInvariantsProcessorSpec.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package processor

import org.scalatestplus.play.PlaySpec
import org.scalatestplus.play.guice.GuiceOneAppPerSuite

class CheckInvariantsProcessorSpec extends PlaySpec with GuiceOneAppPerSuite with db.Helpers {

private def processor: CheckInvariantsProcessor = injector.instanceOf[CheckInvariantsProcessor]

"process" in {
processor.processRecord("periodic")
}
}

0 comments on commit 5bc2774

Please sign in to comment.