Skip to content

Commit

Permalink
Finishing the ScriptEditor (re #294)
Browse files Browse the repository at this point in the history
- Moving lazy variable initialization to a CatalogDB initializer
- Cleanup and document Vizier init sequence.
- Notify user on schema migrations
- Automatically drop documentation modules from scripts.
- CSS polish for ScriptEditor
- Polishing ScriptEditor interface
- Feedback on save
- Save automatically reassigns the URL from project/branch -> script if necessary.
- Added a widget to put all of the URL futzing code in one place.
  • Loading branch information
okennedy committed Jan 5, 2024
1 parent b387f61 commit 585b2a4
Show file tree
Hide file tree
Showing 10 changed files with 428 additions and 109 deletions.
26 changes: 8 additions & 18 deletions vizier/backend/src/info/vizierdb/Vizier.scala
Original file line number Diff line number Diff line change
Expand Up @@ -91,19 +91,6 @@ object Vizier
// Read the above comment before modifying connectionTimeoutMillis please.
)
)

// The following initialize ScalikeJDBC's lazy variables
catalog.Project.columns;
catalog.Branch.columns;
catalog.Workflow.columns;
catalog.Cell.columns;
catalog.Branch.columns;
catalog.Artifact.columns;
catalog.InputArtifactRef.columns;
catalog.OutputArtifactRef.columns;
catalog.Result.columns;
catalog.Script.columns;
catalog.ScriptRevision.columns;
}

def initSpark() =
Expand Down Expand Up @@ -193,20 +180,23 @@ object Vizier
return
}

// Set up the working directory in environments and properties
setWorkingDirectory()

// Check for non-mandatory dependencies
println("Checking for dependencies...")
PythonProcess.checkPython()

// Set up the Vizier directory and database
println("Setting up project library...")
if(!config.basePath().exists) { config.basePath().mkdir() }
initSQLite()
Schema.initialize()
initSQLite() // Connect to the DB
Schema.initialize() // Init the DB and/or apply schema migrations
CatalogDB.initialize() // Load ScalikeJDBC state
bringDatabaseToSaneState() // Clean up 'running' transactions (e.g., from a system crash)
// initORMLogging("warn")
bringDatabaseToSaneState()
setWorkingDirectory()

// Set up Mimir
// Set up Spark/Mimir/etc...
println("Starting Spark...")
initSpark()

Expand Down
26 changes: 26 additions & 0 deletions vizier/backend/src/info/vizierdb/catalog/CatalogDB.scala
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,30 @@ object CatalogDB

def withDBReadOnly[T]( op: DBSession => T ): T =
traceLongHolds( DB.readOnly { implicit s => op(s) })

/**
* Initialize ScalikeJDBC's lazy variables
*
* ScalikeJDBC involves a number of lazy variables that store the actual column names. They are
* initialized by setting up a database connection. Because SQLite is not reentrant, it's not
* possible to initialize them from within a DB Session. Instead, you get a DB 'timeout' as the
* initializer tries and fails to acquire a connection.
*
* Instead of hoping that they get initialized outside of a session, this method explicitly forces
* materialization of all of the lazy variables
*/
def initialize(): Unit =
{
Project.columns;
Branch.columns;
Workflow.columns;
Cell.columns;
Branch.columns;
Artifact.columns;
InputArtifactRef.columns;
OutputArtifactRef.columns;
Result.columns;
Script.columns;
ScriptRevision.columns;
}
}
6 changes: 4 additions & 2 deletions vizier/backend/src/info/vizierdb/catalog/Schema.scala
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,11 @@ object Schema
val requiredMigrations = MIGRATIONS.drop(currentVersion)
if(requiredMigrations.isEmpty){ return }

println(s"... updating vizier.db (old version: $currentVersion; new version: ${MIGRATIONS.size})")

CatalogDB.withDB { implicit session =>
for((migration, idx) <- requiredMigrations.zipWithIndex){
logger.info(s"Applying Migration ${idx + currentVersion}")
for((migration, idx) <- requiredMigrations.zipWithIndex){
logger.info(s"Applying Migration ${idx + currentVersion}: ${migration.getClass.getSimpleName.replace("Migration", "")}")
logger.trace(migration.sql)
migration.apply
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import java.nio.file.{ Files, Paths }
import scala.sys.process.Process
import info.vizierdb.commands.mimir.geocoder.Geocode
import info.vizierdb.commands.mimir.geocoder.TestCaseGeocoder
import info.vizierdb.catalog.CatalogDB

object SharedTestResources
{
Expand Down Expand Up @@ -66,6 +67,7 @@ object SharedTestResources
// Reset the database
Schema.drop
Schema.initialize
CatalogDB.initialize()

// And initialize testing
DummyCommands.init
Expand Down
13 changes: 12 additions & 1 deletion vizier/shared/src/info/vizierdb/serialized/VizierScript.scala
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,18 @@ object VizierScript
branchId = branchId,
workflowId = workflow.id,
modules = workflow.modules.map { module =>
VizierScriptModule.Inline(module, enabled = {module.statev2 == types.ExecutionState.DONE})
val moduleRanSuccessfully = {module.statev2 == types.ExecutionState.DONE}
val moduleInvolvesDocumentation =
module.command.packageId match {
case "docs" => true
case _ => false
}
val shouldEnable = (
moduleRanSuccessfully
&& !moduleInvolvesDocumentation
)

VizierScriptModule.Inline(module, enabled = shouldEnable)
}
)
}
Expand Down
Loading

0 comments on commit 585b2a4

Please sign in to comment.