From: erickson Date: Mon, 7 Jun 2010 19:47:01 +0000 (+0000) Subject: added support for optional task set names; name defaults to start time X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=218a64734e7cc11f1ae3e0a1ea820146fd42295f;p=working%2Frandom.git added support for optional task set names; name defaults to start time git-svn-id: svn://svn.open-ils.org/ILS-Contrib/constrictor/trunk@889 6d9bc8c9-1ec2-4278-b937-99fde70a366f --- diff --git a/constrictor.py b/constrictor.py index 0b6e60097..13ac3f826 100755 --- a/constrictor.py +++ b/constrictor.py @@ -26,6 +26,7 @@ props = None props_filename = PROPS_FILENAME drone_controller = None store_data = True +task_set_name = None def usage(): print ''' @@ -45,6 +46,7 @@ python %s [options] -l listen address for incoming controller connections -x clear the local cache file cache -n do not store the results in the database + -m optional task set name ''' % sys.argv[0] sys.exit(0) @@ -54,9 +56,10 @@ def read_args_and_props(): global props global props_filename global store_data + global task_set_name # see if we have any command-line args that override the properties file - ops, args = getopt.getopt(sys.argv[1:], 's:t:i:d:p:l:f:hxn') + ops, args = getopt.getopt(sys.argv[1:], 's:t:i:d:p:l:f:m:hxn') options = dict( (k,v) for k,v in ops ) if options.has_key('-f'): @@ -79,6 +82,8 @@ def read_args_and_props(): props.set_property('constrictor.port', options['-p']) if options.has_key('-l'): props.set_property('constrictor.listenAddress', options['-l']) + if options.has_key('-m'): + task_set_name = options['-m'] if options.has_key('-n'): store_data = False @@ -135,7 +140,7 @@ if props.get_property('constrictor.listen') == 'true': log_info('running ' + script) f = open_script(scriptDirs, script) if f: - init_db(store_data) + init_db(task_set_name, store_data) try: exec(f) except Exception, e: @@ -148,7 +153,7 @@ if props.get_property('constrictor.listen') == 'true': drone_controller.shutdown() else: - init_db(store_data) + init_db(task_set_name, store_data) script = props.get_property('constrictor.script') # execute the requested script ScriptThread.reset_thread_seed() f = open_script(scriptDirs, script) diff --git a/constrictor/data.py b/constrictor/data.py index ac8d0be70..8ca111327 100644 --- a/constrictor/data.py +++ b/constrictor/data.py @@ -21,7 +21,7 @@ class Data(object): singleton = None - def __init__(self, db_file): + def __init__(self, db_file, task_set_name = None): if Data.singleton is None: log.log_info("sqlite:////%s" % db_file) self.engine = create_engine('sqlite:////%s' % db_file) @@ -30,6 +30,7 @@ class Data(object): self.runtime_data = [] self.task_set_id = None self.insert_data = True + self.task_set_name = task_set_name Data.singleton = self def disconnect(self): @@ -59,6 +60,7 @@ class Data(object): Column('id', Integer, primary_key=True), Column('start_time', Text), Column('end_time', Text), + Column('name', Text), ) if force: @@ -70,12 +72,17 @@ class Data(object): def create_task_set(self): self.task_set_start_time = time.time() + if self.task_set_name is None: + self.task_set_name = self.task_set_start_time if self.insert_data: - res = self.engine.execute( - self.task_set_table.insert().values(start_time = self.task_set_start_time) + self.task_set_table.insert().values( + start_time = self.task_set_start_time, + name = self.task_set_name + ) ) + #self.task_set_id = res.inserted_primary_key self.task_set_id = res.last_inserted_ids()[0] res.close() @@ -137,6 +144,7 @@ class Data(object): # log some basic stats task_set_time = end_time - self.task_set_start_time log.log_info("-"*70) + log.log_info("Task Set -> %s" % str(self.task_set_name)) log.log_info("Task Counts -> %s" % str(task_counts)) log.log_info("Total Tasks -> %d" % len(self.runtime_data)) log.log_info("Total time -> %0.3f seconds" % task_set_time) diff --git a/constrictor/utils.py b/constrictor/utils.py index 9576ccc98..dea42fcae 100755 --- a/constrictor/utils.py +++ b/constrictor/utils.py @@ -48,10 +48,11 @@ def save_props(): print "WARNING: Unable to store properties to file\n%s" % str(e) -def init_db(store_data = True): +def init_db(task_set_name, store_data = True): ''' connect to the db and make sure the tables exist ''' data = constrictor.data.Data( - os.path.join(os.getcwd(), props.get_property('constrictor.dbFile')) + os.path.join(os.getcwd(), props.get_property('constrictor.dbFile')), + task_set_name ) data.insert_data = store_data data.create_schema()