[open-ils-commits] r789 - in constrictor/trunk: . constrictor (erickson)
svn at svn.open-ils.org
svn at svn.open-ils.org
Sun Feb 21 22:10:28 EST 2010
Author: erickson
Date: 2010-02-21 22:10:26 -0500 (Sun, 21 Feb 2010)
New Revision: 789
Modified:
constrictor/trunk/constrictor.py
constrictor/trunk/constrictor/script.py
constrictor/trunk/constrictor/task.py
constrictor/trunk/constrictor/utils.py
Log:
Re-org the data handling.
- data is only written to the DB after all scripts are done. This speeds up the client overall inside the critial code path and removes the requirements for DB semaphores to protect against multi-threaded writes.
- Moved to sqlalchemy instead of the bare mysql layer
- TODO add UI-layer methods back in for generating task summaries, etc.
Modified: constrictor/trunk/constrictor/script.py
===================================================================
--- constrictor/trunk/constrictor/script.py 2010-02-18 22:12:57 UTC (rev 788)
+++ constrictor/trunk/constrictor/script.py 2010-02-22 03:10:26 UTC (rev 789)
@@ -17,7 +17,7 @@
import time, sys, threading
from threading import Thread, local
from properties import Properties
-from db import DBConnection
+import constrictor.data
import threading, traceback
from log import *
@@ -47,7 +47,6 @@
self.script = script # our script object
self.numItr = numItr # number of times to run our script
self.setName(ScriptThread.threadSeed) # use the Thread name as our threadID
- self.dbConnection = None # create this after the thread has launched
self.onComplete = onComplete
ScriptThread.threadSeed += 1
self.userData = None
@@ -82,7 +81,6 @@
data.scriptThread = self
props = Properties.getProperties()
- self.dbConnection = DBConnection(props.getProperty('constrictor.dbFile'))
def getThreadID():
@@ -142,7 +140,7 @@
self.numComplete += 1
if self.numComplete == self.numThreads:
# all threads have completed
- scriptThread.dbConnection.finishTaskSet()
+ constrictor.data.Data.get_instance().store_data()
logInfo('all threads done.. finishing task set')
if ScriptManager.onThreadsComplete:
ScriptManager.onThreadsComplete(ScriptManager)
Modified: constrictor/trunk/constrictor/task.py
===================================================================
--- constrictor/trunk/constrictor/task.py 2010-02-18 22:12:57 UTC (rev 788)
+++ constrictor/trunk/constrictor/task.py 2010-02-22 03:10:26 UTC (rev 789)
@@ -20,6 +20,7 @@
from threading import local
import threading
from log import *
+import constrictor.data
class Task(object):
@@ -61,10 +62,16 @@
self.name, ScriptThread.getThreadID(), self.duration))
sys.stdout.flush()
- dbConn = ScriptThread.currentScriptThread().dbConnection
- dbConn.insertTask(self)
+ constrictor.data.Data.get_instance().add_task(self)
return ret
+ def to_dict(self):
+ return {
+ 'name' : self.name,
+ 'duration' : self.duration,
+ 'success' : self.success,
+ 'thread_id' : ScriptThread.getThreadID()
+ }
Modified: constrictor/trunk/constrictor/utils.py
===================================================================
--- constrictor/trunk/constrictor/utils.py 2010-02-18 22:12:57 UTC (rev 788)
+++ constrictor/trunk/constrictor/utils.py 2010-02-22 03:10:26 UTC (rev 789)
@@ -16,8 +16,8 @@
import sys, getopt, os, errno
from constrictor.properties import Properties
-from constrictor.db import DBConnection
from constrictor.log import *
+import constrictor.data
DEFAULT_PORT = 21800
CONFIG_FILENAME = 'config.xml'
@@ -50,10 +50,12 @@
def initDB():
''' connect to the db and make sure the tables exist '''
- dbConnection = DBConnection(props.getProperty('constrictor.dbFile'))
- dbConnection.createTables()
- dbConnection.createTaskSet()
- dbConnection.disconnect()
+ data = constrictor.data.Data(
+ os.path.join(os.getcwd(), props.getProperty('constrictor.dbFile'))
+ )
+ data.create_schema()
+ data.create_task_set()
+ data.disconnect()
def initDirs():
Modified: constrictor/trunk/constrictor.py
===================================================================
--- constrictor/trunk/constrictor.py 2010-02-18 22:12:57 UTC (rev 788)
+++ constrictor/trunk/constrictor.py 2010-02-22 03:10:26 UTC (rev 789)
@@ -16,11 +16,11 @@
import sys, getopt, os, errno
from constrictor.properties import Properties
-from constrictor.db import DBConnection
from constrictor.controller import DroneController
from constrictor.script import ScriptThread, ScriptManager
from constrictor.log import *
from constrictor.utils import loadProps, saveProps, initDirs, initDB, openScript, PROPS_FILENAME
+import constrictor.data
props = None
props_filename = PROPS_FILENAME
@@ -46,13 +46,6 @@
sys.exit(0)
-
-def onThreadsComplete(scriptManager):
- global droneController
- summary = ScriptThread.currentScriptThread().dbConnection.createTaskSummary()
- droneController.sendResult(type='task_summary', **summary)
-
-
def read_args_and_props():
global props
global props_filename
@@ -86,8 +79,8 @@
def onThreadsComplete(scriptManager):
global droneController
- summary = ScriptThread.currentScriptThread().dbConnection.createTaskSummary()
- droneController.sendResult(type='task_summary', **summary)
+ #summary = ScriptThread.currentScriptThread().dbConnection.createTaskSummary()
+ #droneController.sendResult(type='task_summary', **summary)
read_args_and_props()
initDirs()
More information about the open-ils-commits
mailing list