Commit c4ae1eb9 authored by Peter van 't Hof's avatar Peter van 't Hof
Browse files

Adding pipeline and modules during init

parent 17cbd8cc
......@@ -28,6 +28,9 @@ import scala.collection.mutable
import scala.io.Source
import slick.driver.H2Driver.api._
import scala.concurrent.Await
import scala.concurrent.duration.Duration
/**
* This will collect and write the summary
*
......@@ -59,10 +62,11 @@ class WriteSummary(val parent: SummaryQScript) extends InProcessFunction with Co
case s: MultiSampleQScript => s.initSummaryDb
case _ => qscript.summaryRunId
}
val db = SummaryDb.openSqliteSummary(qscript.summaryDbFile)
db.close()
}
val db = SummaryDb.openSqliteSummary(qscript.summaryDbFile)
val pipelineId = Await.result(db.createPipeline(qscript.summaryName, qscript.summaryRunId), Duration.Inf)
qscript.summarizables.map(x => Await.result(db.createModule(x._1._1, qscript.summaryRunId, pipelineId), Duration.Inf))
db.close()
for (q <- qscript.summaryQScripts)
deps :+= q.summaryFile
for ((_, l) <- qscript.summarizables; s <- l) {
......
......@@ -62,7 +62,7 @@ object SummaryToSqlite extends ToolCommand {
println(Await.result(summary.getLibraries(), Duration.Inf))
val pipelineId = Await.result(summary.createPipeline("pipelineName", runId), Duration.Inf)
val pipelineId = Await.result(summary.forceCreatePipeline("pipelineName", runId), Duration.Inf)
println(Await.result(summary.getPipelines(), Duration.Inf))
......
......@@ -91,11 +91,19 @@ class SummaryDb(db: Database) extends Closeable {
.map(_.headOption.flatten.map(ConfigUtils.jsonTextToMap))
}
def createPipeline(name: String, runId: Int): Future[Int] = {
def forceCreatePipeline(name: String, runId: Int): Future[Int] = {
val id = Await.result(db.run(pipelines.size.result), Duration.Inf)
db.run(pipelines.forceInsert(Pipeline(id, name, runId))).map(_ => id)
}
def createPipeline(name: String, runId: Int): Future[Int] = {
getPipelines(name = Some(name), runId = Some(runId))
.flatMap{ case m =>
if (m.isEmpty) forceCreatePipeline(name, runId)
else Future(m.head.id)
}
}
def getPipelines(pipelineId: Option[Int] = None, name: Option[String] = None, runId: Option[Int] = None) = {
val q = pipelines.filter { lib =>
List(
......@@ -104,14 +112,22 @@ class SummaryDb(db: Database) extends Closeable {
name.map(lib.name === _)
).collect({ case Some(criteria) => criteria }).reduceLeftOption(_ && _).getOrElse(true: Rep[Boolean])
}
db.run(q.map(x => (x.id, x.name, x.runId)).result)
db.run(q.result)
}
def createModule(name: String, runId: Int, pipelineId: Int): Future[Int] = {
def forceCreateModule(name: String, runId: Int, pipelineId: Int): Future[Int] = {
val id = Await.result(db.run(modules.size.result), Duration.Inf)
db.run(modules.forceInsert(Module(id, name, runId, pipelineId))).map(_ => id)
}
def createModule(name: String, runId: Int, pipelineId: Int): Future[Int] = {
getModules(name = Some(name), runId = Some(runId), pipelineId = Some(pipelineId))
.flatMap{ case m =>
if (m.isEmpty) forceCreateModule(name, runId, pipelineId)
else Future(m.head.id)
}
}
def getModules(moduleId: Option[Int] = None, name: Option[String] = None, runId: Option[Int] = None, pipelineId: Option[Int] = None) = {
val q = modules.filter { lib =>
List(
......@@ -121,7 +137,7 @@ class SummaryDb(db: Database) extends Closeable {
name.map(lib.name === _)
).collect({ case Some(criteria) => criteria }).reduceLeftOption(_ && _).getOrElse(true: Rep[Boolean])
}
db.run(q.map(x => (x.id, x.name, x.runId)).result)
db.run(q.result)
}
def createStat(runId: Int, pipelineId: Int, moduleId: Option[Int] = None,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment