From 53d1a86296ae2b312c7c0cf0d949473f328e1f43 Mon Sep 17 00:00:00 2001 From: erickson Date: Thu, 29 Apr 2010 02:55:47 +0000 Subject: [PATCH] make a certain percentage of the batch calls hold/checkout calls. repaired some typos git-svn-id: svn://svn.open-ils.org/ILS-Contrib/constrictor/trunk@875 6d9bc8c9-1ec2-4278-b937-99fde70a366f --- contrib/evergreen/eg_batch.py | 37 ++++++++++++++++++++++++------- contrib/evergreen/eg_circ_misc.py | 4 ++-- contrib/evergreen/eg_data.py | 45 +++++++++++++++++++++++++++++++++++--- contrib/evergreen/eg_tasks.py | 6 ++--- contrib/evergreen/eg_title_hold.py | 4 ++-- contrib/evergreen/eg_workflow.py | 13 ++++++++--- 6 files changed, 88 insertions(+), 21 deletions(-) diff --git a/contrib/evergreen/eg_batch.py b/contrib/evergreen/eg_batch.py index ac538f8ee..32ec881b6 100755 --- a/contrib/evergreen/eg_batch.py +++ b/contrib/evergreen/eg_batch.py @@ -3,11 +3,7 @@ import random, traceback, os 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 @@ class BatchScript(Script): 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 @@ class BatchScript(Script): 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 @@ class BatchScript(Script): 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 @@ class BatchScript(Script): 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()) diff --git a/contrib/evergreen/eg_circ_misc.py b/contrib/evergreen/eg_circ_misc.py index fec089863..022b380db 100644 --- a/contrib/evergreen/eg_circ_misc.py +++ b/contrib/evergreen/eg_circ_misc.py @@ -21,9 +21,9 @@ class CreateTitleHoldScript(Script): 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) diff --git a/contrib/evergreen/eg_data.py b/contrib/evergreen/eg_data.py index e754485df..e81c1bd84 100644 --- a/contrib/evergreen/eg_data.py +++ b/contrib/evergreen/eg_data.py @@ -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 @@ PROP_CONSTRICTOR_THREADS = 'constrictor.numThreads' 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,7 +39,34 @@ class DataManager(object): 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' @@ -59,7 +98,7 @@ class DataManager(object): 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 diff --git a/contrib/evergreen/eg_tasks.py b/contrib/evergreen/eg_tasks.py index 96320308d..9fffb73f0 100644 --- a/contrib/evergreen/eg_tasks.py +++ b/contrib/evergreen/eg_tasks.py @@ -23,7 +23,7 @@ class CheckoutTask(AbstractMethodTask): 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 @@ class RenewTask(AbstractMethodTask): 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 @@ class CheckinTask(AbstractMethodTask): 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] ''' diff --git a/contrib/evergreen/eg_title_hold.py b/contrib/evergreen/eg_title_hold.py index f7706af94..5bc61427d 100644 --- a/contrib/evergreen/eg_title_hold.py +++ b/contrib/evergreen/eg_title_hold.py @@ -14,9 +14,9 @@ class CreateTitleHoldScript(Script): 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()) diff --git a/contrib/evergreen/eg_workflow.py b/contrib/evergreen/eg_workflow.py index a37b4f5e0..46b5ddc9f 100644 --- a/contrib/evergreen/eg_workflow.py +++ b/contrib/evergreen/eg_workflow.py @@ -13,6 +13,10 @@ def do_checkout(copyBarcode, patronID, recurse=False): 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_renew(copyBarcode): 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 @@ def do_title_hold_permit(titleID, patronID, pickupLib): 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 @@ def to_title_hold(titleID, patronID, pickupLib): 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 @@ def to_title_holdCancel(holdID): 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( -- 2.11.0