Skip to content

Commit 585b2a4

Browse files
committed
Finishing the ScriptEditor (re #294)
- 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.
1 parent b387f61 commit 585b2a4

File tree

10 files changed

+428
-109
lines changed

10 files changed

+428
-109
lines changed

vizier/backend/src/info/vizierdb/Vizier.scala

+8-18
Original file line numberDiff line numberDiff line change
@@ -91,19 +91,6 @@ object Vizier
9191
// Read the above comment before modifying connectionTimeoutMillis please.
9292
)
9393
)
94-
95-
// The following initialize ScalikeJDBC's lazy variables
96-
catalog.Project.columns;
97-
catalog.Branch.columns;
98-
catalog.Workflow.columns;
99-
catalog.Cell.columns;
100-
catalog.Branch.columns;
101-
catalog.Artifact.columns;
102-
catalog.InputArtifactRef.columns;
103-
catalog.OutputArtifactRef.columns;
104-
catalog.Result.columns;
105-
catalog.Script.columns;
106-
catalog.ScriptRevision.columns;
10794
}
10895

10996
def initSpark() =
@@ -193,20 +180,23 @@ object Vizier
193180
return
194181
}
195182

183+
// Set up the working directory in environments and properties
184+
setWorkingDirectory()
185+
196186
// Check for non-mandatory dependencies
197187
println("Checking for dependencies...")
198188
PythonProcess.checkPython()
199189

200190
// Set up the Vizier directory and database
201191
println("Setting up project library...")
202192
if(!config.basePath().exists) { config.basePath().mkdir() }
203-
initSQLite()
204-
Schema.initialize()
193+
initSQLite() // Connect to the DB
194+
Schema.initialize() // Init the DB and/or apply schema migrations
195+
CatalogDB.initialize() // Load ScalikeJDBC state
196+
bringDatabaseToSaneState() // Clean up 'running' transactions (e.g., from a system crash)
205197
// initORMLogging("warn")
206-
bringDatabaseToSaneState()
207-
setWorkingDirectory()
208198

209-
// Set up Mimir
199+
// Set up Spark/Mimir/etc...
210200
println("Starting Spark...")
211201
initSpark()
212202

vizier/backend/src/info/vizierdb/catalog/CatalogDB.scala

+26
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,30 @@ object CatalogDB
5858

5959
def withDBReadOnly[T]( op: DBSession => T ): T =
6060
traceLongHolds( DB.readOnly { implicit s => op(s) })
61+
62+
/**
63+
* Initialize ScalikeJDBC's lazy variables
64+
*
65+
* ScalikeJDBC involves a number of lazy variables that store the actual column names. They are
66+
* initialized by setting up a database connection. Because SQLite is not reentrant, it's not
67+
* possible to initialize them from within a DB Session. Instead, you get a DB 'timeout' as the
68+
* initializer tries and fails to acquire a connection.
69+
*
70+
* Instead of hoping that they get initialized outside of a session, this method explicitly forces
71+
* materialization of all of the lazy variables
72+
*/
73+
def initialize(): Unit =
74+
{
75+
Project.columns;
76+
Branch.columns;
77+
Workflow.columns;
78+
Cell.columns;
79+
Branch.columns;
80+
Artifact.columns;
81+
InputArtifactRef.columns;
82+
OutputArtifactRef.columns;
83+
Result.columns;
84+
Script.columns;
85+
ScriptRevision.columns;
86+
}
6187
}

vizier/backend/src/info/vizierdb/catalog/Schema.scala

+4-2
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,11 @@ object Schema
7676
val requiredMigrations = MIGRATIONS.drop(currentVersion)
7777
if(requiredMigrations.isEmpty){ return }
7878

79+
println(s"... updating vizier.db (old version: $currentVersion; new version: ${MIGRATIONS.size})")
80+
7981
CatalogDB.withDB { implicit session =>
80-
for((migration, idx) <- requiredMigrations.zipWithIndex){
81-
logger.info(s"Applying Migration ${idx + currentVersion}")
82+
for((migration, idx) <- requiredMigrations.zipWithIndex){
83+
logger.info(s"Applying Migration ${idx + currentVersion}: ${migration.getClass.getSimpleName.replace("Migration", "")}")
8284
logger.trace(migration.sql)
8385
migration.apply
8486
}

vizier/backend/test/src/info/vizierdb/test/SharedTestResources.scala

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import java.nio.file.{ Files, Paths }
2222
import scala.sys.process.Process
2323
import info.vizierdb.commands.mimir.geocoder.Geocode
2424
import info.vizierdb.commands.mimir.geocoder.TestCaseGeocoder
25+
import info.vizierdb.catalog.CatalogDB
2526

2627
object SharedTestResources
2728
{
@@ -66,6 +67,7 @@ object SharedTestResources
6667
// Reset the database
6768
Schema.drop
6869
Schema.initialize
70+
CatalogDB.initialize()
6971

7072
// And initialize testing
7173
DummyCommands.init

vizier/shared/src/info/vizierdb/serialized/VizierScript.scala

+12-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,18 @@ object VizierScript
4242
branchId = branchId,
4343
workflowId = workflow.id,
4444
modules = workflow.modules.map { module =>
45-
VizierScriptModule.Inline(module, enabled = {module.statev2 == types.ExecutionState.DONE})
45+
val moduleRanSuccessfully = {module.statev2 == types.ExecutionState.DONE}
46+
val moduleInvolvesDocumentation =
47+
module.command.packageId match {
48+
case "docs" => true
49+
case _ => false
50+
}
51+
val shouldEnable = (
52+
moduleRanSuccessfully
53+
&& !moduleInvolvesDocumentation
54+
)
55+
56+
VizierScriptModule.Inline(module, enabled = shouldEnable)
4657
}
4758
)
4859
}

0 commit comments

Comments
 (0)