[open-ils-commits] r757 - in constrictor/trunk: constrictor samples (erickson)
svn at svn.open-ils.org
svn at svn.open-ils.org
Fri Jan 15 14:43:21 EST 2010
Author: erickson
Date: 2010-01-15 14:43:17 -0500 (Fri, 15 Jan 2010)
New Revision: 757
Modified:
constrictor/trunk/constrictor/db.py
constrictor/trunk/constrictor/script.py
constrictor/trunk/constrictor/task.py
constrictor/trunk/samples/sleep.py
Log:
simplified task management. no longer using a task wrapper and task runner to accomodate threads. approach now is to instantiate tasks inside the script (post thread creation). updated sample script. contrib scripts to follow
Modified: constrictor/trunk/constrictor/db.py
===================================================================
--- constrictor/trunk/constrictor/db.py 2010-01-13 22:30:15 UTC (rev 756)
+++ constrictor/trunk/constrictor/db.py 2010-01-15 19:43:17 UTC (rev 757)
@@ -168,19 +168,19 @@
dbSema.release()
return cur
- def insertTask(self, taskRunner):
+ def insertTask(self, task):
from script import ScriptThread
SQL = """
insert into task (task_name, runtime, runner, thread_id, task_set, duration, success)
values ('%s', %f, %d, %d, %d, %f, %d) """ % (
- taskRunner.task.name,
+ task.name,
time.time(),
1, # XXX get me from the task runner ?
ScriptThread.getThreadID(),
DBConnection.taskSetID,
- taskRunner.duration,
- taskRunner.success
+ task.duration,
+ task.success
)
self.execute(SQL, True)
Modified: constrictor/trunk/constrictor/script.py
===================================================================
--- constrictor/trunk/constrictor/script.py 2010-01-13 22:30:15 UTC (rev 756)
+++ constrictor/trunk/constrictor/script.py 2010-01-15 19:43:17 UTC (rev 757)
@@ -18,7 +18,7 @@
from threading import Thread, local
from properties import Properties
from db import DBConnection
-import threading
+import threading, traceback
from log import *
@@ -66,6 +66,7 @@
try:
self.script.run()
except Exception, e:
+ traceback.print_exc()
logError("Script exception: %s" % str(e))
break
Modified: constrictor/trunk/constrictor/task.py
===================================================================
--- constrictor/trunk/constrictor/task.py 2010-01-13 22:30:15 UTC (rev 756)
+++ constrictor/trunk/constrictor/task.py 2010-01-15 19:43:17 UTC (rev 757)
@@ -30,53 +30,31 @@
def __init__(self, name=''):
self.name = name
+ self.duration = 0
+ self.success = False
+ self.complete = False
+
def run(self, **kwargs):
"""Override this method with the work to perform"""
logError('Override me!')
- def wrap(self):
- """ Static method for wrapping and registering a task.
- Statistics will only be collected for registered tasks.
- """
- return TaskWrapper(self)
+ def start(self, **kwargs):
-class TaskWrapper(object):
- """ Provides a new run() method for the client to call directly.
- The main purpose of the TaskWrapper is to allow the creation of
- a TaskRunner after thread creation.
- """
-
- def __init__(self, task):
- self.task = task
- def run(self, **kwargs):
- return TaskRunner(self.task).go(**kwargs)
-
-
-
-class TaskRunner(object):
- """ Runs a single task and collects timing information on the task for a given thread. """
-
- def __init__(self, task):
- self.task = task
- self.duration = 0
- self.success = False
- self.complete = False
-
- def go(self, **kwargs):
- start = time.time()
ret = None # capture the return value from the task
+ start = time.time()
try:
- ret = self.task.run(**kwargs)
+ ret = self.run(**kwargs)
self.duration = time.time() - start
self.complete = True
self.success = True
+
except Exception, E:
sys.stderr.write(str(E))
# store the error info somewhere?
logDebug('%s: thread = %d : duration = %f' % (
- self.task.name, ScriptThread.getThreadID(), self.duration))
+ self.name, ScriptThread.getThreadID(), self.duration))
sys.stdout.flush()
dbConn = ScriptThread.currentScriptThread().dbConnection
Modified: constrictor/trunk/samples/sleep.py
===================================================================
--- constrictor/trunk/samples/sleep.py 2010-01-13 22:30:15 UTC (rev 756)
+++ constrictor/trunk/samples/sleep.py 2010-01-15 19:43:17 UTC (rev 757)
@@ -26,22 +26,13 @@
return self.name
-# wrap the tasks so they can be analyzed
-task = MyTask('task1').wrap()
-task2 = MyTask('task2').wrap()
-task3 = MyTask('task3').wrap()
-task4 = MyTask('task4').wrap()
-
-
class MyScript(Script):
''' Subclass the Script class, define the run() method '''
def run(self):
- ret = task.run()
- ret = task2.run()
- ret = task3.run()
- ret = task4.run()
- ret = task.run()
- ret = task2.run()
+
+ for task in ['task1', 'task2', 'task3', 'task4', 'task1', 'task2']:
+ MyTask(task).start()
+
return True
# Launch the script
More information about the open-ils-commits
mailing list