From eb66079172e8ef3aa44e3fecf1381673d48d1ab4 Mon Sep 17 00:00:00 2001 From: erickson Date: Thu, 13 Aug 2009 17:12:43 +0000 Subject: [PATCH] used new hold id returned from place hold method to subsequently cancel placed hold. props_filename is a global var, fixed git-svn-id: svn://svn.open-ils.org/ILS-Contrib/constrictor/trunk@615 6d9bc8c9-1ec2-4278-b937-99fde70a366f --- constrictor.py | 1 + contrib/evergreen/eg_tasks.py | 4 ++-- contrib/evergreen/eg_title_hold.py | 20 +++----------------- contrib/evergreen/eg_workflow.py | 10 ++++++---- 4 files changed, 12 insertions(+), 23 deletions(-) diff --git a/constrictor.py b/constrictor.py index c12b5c317..eaab16a61 100755 --- a/constrictor.py +++ b/constrictor.py @@ -55,6 +55,7 @@ def onThreadsComplete(scriptManager): def read_args_and_props(): global props + global props_filename # 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:h') diff --git a/contrib/evergreen/eg_tasks.py b/contrib/evergreen/eg_tasks.py index 9c3c93f12..8f8d267e4 100644 --- a/contrib/evergreen/eg_tasks.py +++ b/contrib/evergreen/eg_tasks.py @@ -2,7 +2,7 @@ from constrictor.task import Task from constrictor.log import * import eg_utils from oils.const import * -from osrf.net_obj import * +import osrf.net_obj TASKS = {} @@ -115,7 +115,7 @@ class TitleHoldTask(AbstractMethodTask): kw[pickup_lib] ''' # construct the hold object - hold = osrfNetworkObject.ahr() + hold = osrf.net_obj.NetworkObject.ahr() hold.pickup_lib(kw['pickup_lib']) hold.usr(kw['patron_id']) hold.target(kw['title_id']) diff --git a/contrib/evergreen/eg_title_hold.py b/contrib/evergreen/eg_title_hold.py index a5a3d04a7..5ac5e1f44 100644 --- a/contrib/evergreen/eg_title_hold.py +++ b/contrib/evergreen/eg_title_hold.py @@ -14,8 +14,6 @@ class CreateTitleHoldScript(Script): eg_utils.initThread() dm = DataManager() patronID = dm.getThreadData(PROP_PATRON_IDS) - scriptThread.userData = doTitleHoldFetchAll(patronID) - logDebug("init: grabbed existing holds %s" % str([ int(i) for i in scriptThread.userData])) def run(self): @@ -25,21 +23,9 @@ class CreateTitleHoldScript(Script): pickupLib = dm.getThreadData(PROP_ORG_IDS) patronID = dm.getThreadData(PROP_PATRON_IDS) - doTitleHold(titleID, patronID, pickupLib) - - # XXX TODO update EG to return hold IDs for new holds so - # that this script does not have to manually sort through - # the holds to find what to clean up - - # go ahead and cancel any new holds - allHolds = doTitleHoldFetchAll(patronID) - logDebug("grabbed all holds %s" % str([ int(i) for i in allHolds])) - - scriptThread = ScriptThread.currentScriptThread() - cancelHolds = [ h for h in allHolds if h not in scriptThread.userData ] - - for hold in cancelHolds: - doTitleHoldCancel(hold) + hold_id = doTitleHold(titleID, patronID, pickupLib) + if hold_id: + doTitleHoldCancel(hold_id) diff --git a/contrib/evergreen/eg_workflow.py b/contrib/evergreen/eg_workflow.py index d190d7b96..2223d9272 100644 --- a/contrib/evergreen/eg_workflow.py +++ b/contrib/evergreen/eg_workflow.py @@ -77,7 +77,7 @@ def doTitleHoldPermit(titleID, patronID, pickupLib): "TitleHoldPermit(%s, %s, %s) failed -> %s" % ( titleID, patronID, pickupLib, osrf.json.to_json(evt))) - if str(evt) != '1': + if str(evt['success']) != '1': logInfo("TitleHoldPermit(%s, %s, %s) not allowed -> %s" % ( titleID, patronID, pickupLib, evt)) return None @@ -92,6 +92,8 @@ def doTitleHold(titleID, patronID, pickupLib): return evt = TASKS['TitleHoldTask'].run(title_id=titleID, patron_id=patronID, pickup_lib=pickupLib) + + logInfo("title task returned %s" % str(evt)) if isinstance(evt, list): evts = [] @@ -104,20 +106,20 @@ def doTitleHold(titleID, patronID, pickupLib): logInfo("TitleHold(%s, %s, %s) -> %s" % (titleID, patronID, pickupLib, Event.parse_event(evt).code)) return None - if str(evt) != '1': + if str(evt) == '-1': logInfo("TitleHold(%s, %s, %s) placement failed: %s" % ( titleID, patronID, pickupLib, str(evt))) return None logInfo('TitleHold(%s, %s, %s) -> SUCCESS' % (titleID, patronID, pickupLib)) - return True + return int(evt) # new hold ID def doTitleHoldCancel(holdID): evt = TASKS['TitleHoldCancelTask'].run(hold_id=holdID) - evt_txt = Event.parse_event(evt).text_code if Event.parse_event(evt): + evt_txt = Event.parse_event(evt).text_code if evt_txt == 'ACTION_HOLD_REQUEST_NOT_FOUND': return True raise ILSEventException( -- 2.11.0