[open-ils-commits] r875 - constrictor/trunk/contrib/evergreen (erickson)

svn at svn.open-ils.org svn at svn.open-ils.org
Wed Apr 28 22:55:50 EDT 2010


Author: erickson
Date: 2010-04-28 22:55:47 -0400 (Wed, 28 Apr 2010)
New Revision: 875

Modified:
   constrictor/trunk/contrib/evergreen/eg_batch.py
   constrictor/trunk/contrib/evergreen/eg_circ_misc.py
   constrictor/trunk/contrib/evergreen/eg_data.py
   constrictor/trunk/contrib/evergreen/eg_tasks.py
   constrictor/trunk/contrib/evergreen/eg_title_hold.py
   constrictor/trunk/contrib/evergreen/eg_workflow.py
Log:
make a certain percentage of the batch calls hold/checkout calls.  repaired some typos

Modified: constrictor/trunk/contrib/evergreen/eg_batch.py
===================================================================
--- constrictor/trunk/contrib/evergreen/eg_batch.py	2010-04-28 18:52:46 UTC (rev 874)
+++ constrictor/trunk/contrib/evergreen/eg_batch.py	2010-04-29 02:55:47 UTC (rev 875)
@@ -3,11 +3,7 @@
 from constrictor.script import Script, ScriptThread
 from constrictor.properties import Properties
 import constrictor.log as log
-import eg_utils
-import eg_data
-import eg_workflow
-import eg_tasks
-import osrf.json
+import eg_utils, eg_data, eg_workflow, eg_tasks, osrf.json
 
 eg_utils.init()
 props = Properties.get_properties()
@@ -37,7 +33,8 @@
         self.org_unis = []
 
 
-    def fetch_dynamic_data(self):
+    '''
+    def _fetch_dynamic_data(self):
         pcrud = 'open-ils.pcrud'
         method = 'open-ils.pcrud.search.%s.atomic'
         
@@ -58,17 +55,18 @@
 
         self.data_mgr.insert_prop_data(eg_data.PROP_TITLE_ID, [obj.id() for obj in self.bibs])
         self.data_mgr.insert_prop_data(eg_data.PROP_COPY_ID, [obj.id() for obj in self.copies])
-        self.data_mgr.insert_prop_data(eg_data.PROP_COPY_BARCODE, [obj.id() for obj in self.copies])
+        self.data_mgr.insert_prop_data(eg_data.PROP_COPY_BARCODE, [obj.barcode() for obj in self.copies])
         self.data_mgr.insert_prop_data(eg_data.PROP_CALLNUMBER_ID, [obj.id() for obj in self.call_numbers])
         self.data_mgr.insert_prop_data(eg_data.PROP_ORG_ID, [obj.id() for obj in self.org_units])
         self.data_mgr.insert_prop_data(eg_data.PROP_ORG_SHORTNAME, [obj.shortname() for obj in self.org_units])
+    '''
 
     def load_file(self):
         
         batch_file = props.get_property('evergreen.batchAPIFile')
         log.log_info("loading " + batch_file)
         self.data_mgr = eg_data.DataManager()
-        self.fetch_dynamic_data()
+        self.data_mgr.fetch_dynamic_data()
 
         file = open(batch_file)
         for line in file.readlines():
@@ -128,6 +126,25 @@
 
         file.close()
 
+    def run_xact_chunk(self):
+        '''
+        Performs a batch of transactions: holds, checkout, renewal, checkin
+        '''
+
+        title_id = self.data_mgr.get_thread_data(eg_data.PROP_TITLE_ID)
+        pickup_lib = self.data_mgr.get_thread_data(eg_data.PROP_ORG_ID)
+        patron_id = self.data_mgr.get_thread_data(eg_data.PROP_PATRON_ID)
+        copy_barcode = self.data_mgr.get_thread_data(eg_data.PROP_COPY_BARCODE, True)
+
+        # title hold
+        hold_id = eg_workflow.do_title_hold(title_id, patron_id, pickup_lib)
+        if hold_id: 
+            eg_workflow.do_title_holdCancel(hold_id)
+        eg_workflow.do_checkout(copy_barcode, patron_id)
+        eg_workflow.do_renew(copy_barcode)
+        eg_workflow.do_checkin(copy_barcode)
+
+
     def run(self):
 
         if not self.loaded:
@@ -141,6 +158,10 @@
                 log.log_error("Batch Method Error")
                 traceback.print_exc()
 
+            # hard-coded percentage of circ/hold transactions for now.
+            if idx % 20 == 0:
+                self.run_xact_chunk()
 
 
+
 ScriptManager.go(BatchScript())

Modified: constrictor/trunk/contrib/evergreen/eg_circ_misc.py
===================================================================
--- constrictor/trunk/contrib/evergreen/eg_circ_misc.py	2010-04-28 18:52:46 UTC (rev 874)
+++ constrictor/trunk/contrib/evergreen/eg_circ_misc.py	2010-04-29 02:55:47 UTC (rev 875)
@@ -21,9 +21,9 @@
         if not bib: return False
 
         # title hold
-        hold_id = to_title_hold(title_id, patron_id, pickup_lib)
+        hold_id = do_title_hold(title_id, patron_id, pickup_lib)
         if hold_id:
-            to_title_holdCancel(hold_id)
+            do_title_holdCancel(hold_id)
 
         # checkout/renew/checkin
         evt = do_checkout(copy_barcode, patron_id)

Modified: constrictor/trunk/contrib/evergreen/eg_data.py
===================================================================
--- constrictor/trunk/contrib/evergreen/eg_data.py	2010-04-28 18:52:46 UTC (rev 874)
+++ constrictor/trunk/contrib/evergreen/eg_data.py	2010-04-29 02:55:47 UTC (rev 875)
@@ -1,7 +1,8 @@
 from constrictor.properties import Properties
 from constrictor.script import ScriptThread
-from constrictor.log import *
+import constrictor.log as log
 from oils.utils.utils import unique
+import eg_tasks, eg_utils, osrf.json
 
 PROP_USERNAME = 'evergreen.username'
 PROP_PASSWORD = 'evergreen.password'
@@ -20,6 +21,17 @@
 class DataManagerException(Exception):
     pass
 
+class DataMethodTask(eg_tasks.AbstractMethodTask):
+    def __init__(self, service, method):
+        eg_tasks.AbstractMethodTask.__init__(self, method)
+        self.service = service
+        self.method = method
+
+    def run(self, **kw):
+        log.log_info("Data Method: %s %s" % (self.method, osrf.json.to_json(kw['params'])))
+        return self.run_method(*kw['params'])
+
+
 class DataManager(object):
     ''' This module manages a global cache of test data '''
 
@@ -27,8 +39,35 @@
         self.data = {}
         self.props = Properties.get_properties()
         self.read_props()
-        log_debug(self)
+        log.log_debug(self)
 
+    def fetch_dynamic_data(self):
+        pcrud = 'open-ils.pcrud'
+        method = 'open-ils.pcrud.search.%s.atomic'
+        
+        auth = eg_utils.authtoken()
+        thread_count = self.props.get_property('constrictor.numThreads')
+
+        bibs = DataMethodTask(pcrud, method % 'bre').start(
+            params = [auth, {'deleted' : 'f', 'id' : {'>' : 0}}, {'limit' : thread_count}])
+
+        copies = DataMethodTask(pcrud, method % 'acp').start(
+            params = [auth, {'deleted' : 'f', 'id' : {'>' : 0}}, {'limit' : thread_count}])
+
+        call_numbers = DataMethodTask(pcrud, method % 'acn').start(
+            params = [auth, {'deleted' : 'f', 'id' : {'>' : 0}}, {'limit' : thread_count}])
+
+        org_units = DataMethodTask(pcrud, method % 'aou').start(
+            params = [auth, {'id' : {'>' : 0}}, {'limit' : thread_count}])
+
+        self.insert_prop_data(PROP_TITLE_ID, [obj.id() for obj in bibs])
+        self.insert_prop_data(PROP_COPY_ID, [obj.id() for obj in copies])
+        self.insert_prop_data(PROP_COPY_BARCODE, [obj.barcode() for obj in copies])
+        self.insert_prop_data(PROP_CALLNUMBER_ID, [obj.id() for obj in call_numbers])
+        self.insert_prop_data(PROP_ORG_ID, [obj.id() for obj in org_units])
+        self.insert_prop_data(PROP_ORG_SHORTNAME, [obj.shortname() for obj in org_units])
+
+
     def __str__(self):
         s = 'DataManager() read properties:\n'
         for p in [
@@ -59,7 +98,7 @@
         if split and v:
             v = unique(v.split(','))
         self.data[prop] = v
-        log_debug("DataManager set property %s => %s" % (prop, str(v)))
+        log.log_debug("DataManager set property %s => %s" % (prop, str(v)))
 
     def insert_prop_data(self, prop, array):
         self.data[prop] = array

Modified: constrictor/trunk/contrib/evergreen/eg_tasks.py
===================================================================
--- constrictor/trunk/contrib/evergreen/eg_tasks.py	2010-04-28 18:52:46 UTC (rev 874)
+++ constrictor/trunk/contrib/evergreen/eg_tasks.py	2010-04-29 02:55:47 UTC (rev 875)
@@ -23,7 +23,7 @@
     def __init__(self):
         AbstractMethodTask.__init__(self)
         self.service = OILS_APP_CIRC
-        self.method = 'open-ils.circ.checkout.full'
+        self.method = 'open-ils.circ.checkout.full.override'
 
     def run(self, **kw):
         ''' kw[copy_barcode] The item barcode
@@ -37,7 +37,7 @@
     def __init__(self):
         AbstractMethodTask.__init__(self)
         self.service = OILS_APP_CIRC
-        self.method = 'open-ils.circ.renew'
+        self.method = 'open-ils.circ.renew.override'
 
     def run(self, **kw):
         ''' kw[copy_barcode] The item barcode '''
@@ -50,7 +50,7 @@
     def __init__(self):
         AbstractMethodTask.__init__(self)
         self.service = OILS_APP_CIRC
-        self.method = 'open-ils.circ.checkin'
+        self.method = 'open-ils.circ.checkin.override'
 
     def run(self, **kw):
         ''' kw[copy_barcode] '''

Modified: constrictor/trunk/contrib/evergreen/eg_title_hold.py
===================================================================
--- constrictor/trunk/contrib/evergreen/eg_title_hold.py	2010-04-28 18:52:46 UTC (rev 874)
+++ constrictor/trunk/contrib/evergreen/eg_title_hold.py	2010-04-29 02:55:47 UTC (rev 875)
@@ -14,9 +14,9 @@
         pickup_lib = dm.get_thread_data(PROP_ORG_ID)
         patron_id = dm.get_thread_data(PROP_PATRON_ID)
 
-        hold_id = to_title_hold(title_id, patron_id, pickup_lib)
+        hold_id = do_title_hold(title_id, patron_id, pickup_lib)
         if hold_id:
-            to_title_holdCancel(hold_id)
+            do_title_holdCancel(hold_id)
 
 ScriptManager.go(CreateTitleHoldScript())
 

Modified: constrictor/trunk/contrib/evergreen/eg_workflow.py
===================================================================
--- constrictor/trunk/contrib/evergreen/eg_workflow.py	2010-04-28 18:52:46 UTC (rev 874)
+++ constrictor/trunk/contrib/evergreen/eg_workflow.py	2010-04-29 02:55:47 UTC (rev 875)
@@ -13,6 +13,10 @@
 
     evt = eg_tasks.CheckoutTask().start(
         copy_barcode=copyBarcode, patron_id=patronID)
+
+    if not evt:
+        return None
+
     evt_txt = Event.parse_event(evt).text_code
     log_info("Checkout(%s,%s) -> %s" % (copyBarcode, patronID, evt_txt))
 
@@ -47,6 +51,9 @@
 def do_checkin(copyBarcode):
 
     evt = eg_tasks.CheckinTask().start(copy_barcode=copyBarcode)
+    if not evt:
+        return Non
+
     evt_txt = Event.parse_event(evt).text_code
     log_info("Checkin(%s) -> %s" % (copyBarcode, evt_txt))
 
@@ -87,7 +94,7 @@
     return True
 
 
-def to_title_hold(titleID, patronID, pickupLib):
+def do_title_hold(titleID, patronID, pickupLib):
 
     if not do_title_hold_permit(titleID, patronID, pickupLib):
         return
@@ -115,7 +122,7 @@
     log_info('TitleHold(%s, %s, %s) -> SUCCESS' % (titleID, patronID, pickupLib))
     return int(evt) # new hold ID
 
-def to_title_holdCancel(holdID):
+def do_title_holdCancel(holdID):
 
     evt = eg_tasks.TitleHoldCancelTask().start(hold_id=holdID)
 
@@ -129,7 +136,7 @@
     log_info('TitleHoldCancel(%s) -> SUCCESS' % holdID)
     return True
 
-def to_title_holdFetchAll(patronID):
+def do_title_holdFetchAll(patronID):
     evt = eg_tasks.TitleHoldFetchAllTask().start(patron_id=patronID)
     if Event.parse_event(evt):
         raise ILSEventException(



More information about the open-ils-commits mailing list