[open-ils-commits] r760 - constrictor/trunk/contrib/evergreen (erickson)
svn at svn.open-ils.org
svn at svn.open-ils.org
Fri Jan 15 15:29:31 EST 2010
Author: erickson
Date: 2010-01-15 15:29:26 -0500 (Fri, 15 Jan 2010)
New Revision: 760
Modified:
constrictor/trunk/contrib/evergreen/eg_bib_search.py
constrictor/trunk/contrib/evergreen/eg_tasks.py
constrictor/trunk/contrib/evergreen/eg_user_search.py
constrictor/trunk/contrib/evergreen/eg_user_transactions.py
constrictor/trunk/contrib/evergreen/eg_workflow.py
Log:
updated contrib scripts to use new-style per-thread tasks
Modified: constrictor/trunk/contrib/evergreen/eg_bib_search.py
===================================================================
--- constrictor/trunk/contrib/evergreen/eg_bib_search.py 2010-01-15 20:04:39 UTC (rev 759)
+++ constrictor/trunk/contrib/evergreen/eg_bib_search.py 2010-01-15 20:29:26 UTC (rev 760)
@@ -4,11 +4,6 @@
import eg_utils, eg_data, eg_tasks
import random
-eg_utils.init()
-words_file = open('/usr/share/dict/words') # add config property
-words = words_file.readlines()
-words_file.close()
-
class BibSearchScript(Script):
def run(self):
@@ -25,7 +20,7 @@
search_term = eg_utils.random_phrase(None, 3) # search phrase has 1-3 words
logInfo('Search term="%s" args="%s"' % (search_term, str(search_args)))
- res = eg_tasks.TASKS['BibSearchTask'].run(
+ res = eg_tasks.BibSearchTask().start(
search_args = search_args,
search_term = search_term
)
@@ -33,6 +28,10 @@
logInfo('Search returned %d hits' % int(res['count']))
return True
+eg_utils.init()
+words_file = open('/usr/share/dict/words') # add config property
+words = words_file.readlines()
+words_file.close()
ScriptManager.go(BibSearchScript())
Modified: constrictor/trunk/contrib/evergreen/eg_tasks.py
===================================================================
--- constrictor/trunk/contrib/evergreen/eg_tasks.py 2010-01-15 20:04:39 UTC (rev 759)
+++ constrictor/trunk/contrib/evergreen/eg_tasks.py 2010-01-15 20:29:26 UTC (rev 760)
@@ -4,11 +4,6 @@
from oils.const import *
import osrf.net_obj
-TASKS = {}
-
-def registerTask(task):
- TASKS[task.name] = task.wrap()
-
class AbstractMethodTask(Task):
''' Generic superclass for tasks that perform a single
server-side operation '''
@@ -23,9 +18,6 @@
def runMethod(self, *args):
return eg_utils.request(self.service, self.method, *args).send()
- def register(self):
- TASKS[self.name] = self.wrap()
-
class CheckoutTask(AbstractMethodTask):
def __init__(self):
@@ -40,9 +32,7 @@
return self.runMethod(eg_utils.authtoken(), dict(kw))
-registerTask(CheckoutTask())
-
class RenewTask(AbstractMethodTask):
def __init__(self):
AbstractMethodTask.__init__(self)
@@ -54,9 +44,7 @@
return self.runMethod(eg_utils.authtoken(), dict(kw))
-registerTask(RenewTask())
-
class CheckinTask(AbstractMethodTask):
def __init__(self):
@@ -68,9 +56,7 @@
''' kw[copy_barcode] '''
return self.runMethod(eg_utils.authtoken(), dict(kw))
-registerTask(CheckinTask())
-
class AbortTransitTask(AbstractMethodTask):
def __init__(self):
AbstractMethodTask.__init__(self)
@@ -81,28 +67,24 @@
''' kw[copy_barcode] '''
return self.runMethod(eg_utils.authtoken(), {"barcode":kw['copy_barcode']})
-registerTask(AbortTransitTask())
-class TitleHoldPermitTask(AbstractMethodTask):
- def __init__(self):
- AbstractMethodTask.__init__(self)
- self.service = OILS_APP_CIRC
- self.method = 'open-ils.circ.title_hold.is_possible'
+class TitleHoldPermitTask(AbstractMethodTask):
+ def __init__(self):
+ AbstractMethodTask.__init__(self)
+ self.service = OILS_APP_CIRC
+ self.method = 'open-ils.circ.title_hold.is_possible'
+
+ def run(self, **kw):
+ ''' kw[title_id]
+ kw[patron_id]
+ kw[pickup_lib]
+ '''
+ return self.runMethod(eg_utils.authtoken(), {
+ "patronid" : kw['patron_id'],
+ "titleid" : kw['title_id'],
+ "pickup_lib" : kw['pickup_lib']})
- def run(self, **kw):
- ''' kw[title_id]
- kw[patron_id]
- kw[pickup_lib]
- '''
- return self.runMethod(eg_utils.authtoken(), {
- "patronid" : kw['patron_id'],
- "titleid" : kw['title_id'],
- "pickup_lib" : kw['pickup_lib']})
-registerTask(TitleHoldPermitTask())
-
-
-
class TitleHoldTask(AbstractMethodTask):
def __init__(self):
AbstractMethodTask.__init__(self)
@@ -123,9 +105,7 @@
return self.runMethod(eg_utils.authtoken(), hold)
-registerTask(TitleHoldTask())
-
class TitleHoldCancelTask(AbstractMethodTask):
def __init__(self):
AbstractMethodTask.__init__(self)
@@ -136,9 +116,7 @@
''' kw['hold_id'] '''
return self.runMethod(eg_utils.authtoken(), kw['hold_id'])
-registerTask(TitleHoldCancelTask())
-
class TitleHoldFetchAllTask(AbstractMethodTask):
def __init__(self):
@@ -150,8 +128,6 @@
''' kw['patron_id'] '''
return self.runMethod(eg_utils.authtoken(), kw['patron_id'])
-registerTask(TitleHoldFetchAllTask())
-
class BibSearchTask(AbstractMethodTask):
def __init__(self):
@@ -162,8 +138,6 @@
def run(self, **kw):
return self.runMethod(kw['search_args'], kw['search_term'], True)
-registerTask(BibSearchTask())
-
class UserTransactionsByType(AbstractMethodTask):
def __init__(self):
@@ -174,8 +148,6 @@
self.method = kw['method']
return self.runMethod(eg_utils.authtoken(), kw['user_id'])
-registerTask(UserTransactionsByType())
-
class UserSearchTask(AbstractMethodTask):
def __init__(self):
@@ -186,5 +158,3 @@
def run(self, **kw):
return self.runMethod(eg_utils.authtoken(), kw['search_args'], 100)
-registerTask(UserSearchTask())
-
Modified: constrictor/trunk/contrib/evergreen/eg_user_search.py
===================================================================
--- constrictor/trunk/contrib/evergreen/eg_user_search.py 2010-01-15 20:04:39 UTC (rev 759)
+++ constrictor/trunk/contrib/evergreen/eg_user_search.py 2010-01-15 20:29:26 UTC (rev 760)
@@ -1,4 +1,3 @@
-from constrictor.task import Task
from constrictor.script import Script, ScriptManager, ScriptThread
from constrictor.log import *
import eg_utils, eg_data, eg_tasks
@@ -21,7 +20,7 @@
logInfo('Search for patron %s' % str(search_args))
try:
- res = eg_tasks.TASKS['UserSearchTask'].run(search_args = search_args)
+ res = eg_tasks.UserSearchTask().start(search_args = search_args)
logInfo('Search returned %d hits' % len(res))
except Exception, e:
Modified: constrictor/trunk/contrib/evergreen/eg_user_transactions.py
===================================================================
--- constrictor/trunk/contrib/evergreen/eg_user_transactions.py 2010-01-15 20:04:39 UTC (rev 759)
+++ constrictor/trunk/contrib/evergreen/eg_user_transactions.py 2010-01-15 20:29:26 UTC (rev 760)
@@ -29,7 +29,7 @@
for type in types:
logInfo('Loading patron(%s) transactions with %s' % (int(user_id), type))
- res = eg_tasks.TASKS['UserTransactionsByType'].run(
+ res = eg_tasks.UserTransactionsByType().start(
method = type,
user_id = user_id
)
Modified: constrictor/trunk/contrib/evergreen/eg_workflow.py
===================================================================
--- constrictor/trunk/contrib/evergreen/eg_workflow.py 2010-01-15 20:04:39 UTC (rev 759)
+++ constrictor/trunk/contrib/evergreen/eg_workflow.py 2010-01-15 20:29:26 UTC (rev 760)
@@ -1,4 +1,4 @@
-from eg_tasks import TASKS
+import eg_tasks
from eg_data import DataManager
from eg_utils import ILSEventException
from constrictor.log import *
@@ -11,7 +11,7 @@
def doCheckout(copyBarcode, patronID, recurse=False):
- evt = TASKS['CheckoutTask'].run(
+ evt = eg_tasks.CheckoutTask().start(
copy_barcode=copyBarcode, patron_id=patronID)
evt_txt = Event.parse_event(evt).text_code
logInfo("Checkout(%s,%s) -> %s" % (copyBarcode, patronID, evt_txt))
@@ -32,7 +32,7 @@
def doRenew(copyBarcode):
- evt = TASKS['RenewTask'].run(copy_barcode=copyBarcode)
+ evt = eg_tasks.RenewTask().start(copy_barcode=copyBarcode)
evt_txt = Event.parse_event(evt).text_code
logInfo("Renew(%s) -> %s" % (copyBarcode, evt_txt))
@@ -45,7 +45,7 @@
def doCheckin(copyBarcode):
- evt = TASKS['CheckinTask'].run(copy_barcode=copyBarcode)
+ evt = eg_tasks.CheckinTask().start(copy_barcode=copyBarcode)
evt_txt = Event.parse_event(evt).text_code
logInfo("Checkin(%s) -> %s" % (copyBarcode, evt_txt))
@@ -55,7 +55,7 @@
if evt_txt == 'ROUTE_ITEM':
logInfo("Cancelling post-checkin transit...")
- res = TASKS['AbortTransitTask'].run(copy_barcode=copyBarcode)
+ res = eg_tasks.AbortTransitTask().start(copy_barcode=copyBarcode)
if Event.parse_event(res): # transit returns "1" on success
logError("Unable to abort transit for %s : %s" % (copyBarcode, osrf.json.to_json(evt)))
@@ -69,7 +69,7 @@
def doTitleHoldPermit(titleID, patronID, pickupLib):
- evt = TASKS['TitleHoldPermitTask'].run(
+ evt = eg_tasks.TitleHoldPermitTask().start(
title_id=titleID, patron_id=patronID, pickup_lib=pickupLib)
if Event.parse_event(evt):
@@ -91,7 +91,7 @@
if not doTitleHoldPermit(titleID, patronID, pickupLib):
return
- evt = TASKS['TitleHoldTask'].run(title_id=titleID, patron_id=patronID, pickup_lib=pickupLib)
+ evt = et_tasks.TitleHoldTask().start(title_id=titleID, patron_id=patronID, pickup_lib=pickupLib)
logInfo("title task returned %s" % str(evt))
@@ -116,7 +116,7 @@
def doTitleHoldCancel(holdID):
- evt = TASKS['TitleHoldCancelTask'].run(hold_id=holdID)
+ evt = eg_tasks.TitleHoldCancelTask().start(hold_id=holdID)
if Event.parse_event(evt):
evt_txt = Event.parse_event(evt).text_code
@@ -129,7 +129,7 @@
return True
def doTitleHoldFetchAll(patronID):
- evt = TASKS['TitleHoldFetchAllTask'].run(patron_id=patronID)
+ evt = eg_tasks.TitleHoldFetchAllTask().start(patron_id=patronID)
if Event.parse_event(evt):
raise ILSEventException(
"TitleHoldFetchAll(%s) failed -> %s" % (patronID, evt))
More information about the open-ils-commits
mailing list