[Checkins] SVN: transaction/branches/chrism-job/ allow args to be passed to wrapped function, add rudimentary docs to CHANGES.txt

Chris McDonough cvs-admin at zope.org
Wed Apr 4 08:18:30 UTC 2012


Log message for revision 124930:
  allow args to be passed to wrapped function, add rudimentary docs to CHANGES.txt

Changed:
  U   transaction/branches/chrism-job/CHANGES.txt
  U   transaction/branches/chrism-job/transaction/_manager.py
  U   transaction/branches/chrism-job/transaction/tests/test_manager.py

-=-
Modified: transaction/branches/chrism-job/CHANGES.txt
===================================================================
--- transaction/branches/chrism-job/CHANGES.txt	2012-04-04 07:59:18 UTC (rev 124929)
+++ transaction/branches/chrism-job/CHANGES.txt	2012-04-04 08:18:26 UTC (rev 124930)
@@ -13,6 +13,37 @@
   first attempt to generate an exception during commit would cause that
   exception to be raised).
 
+- Add a ``job`` function to the ``TransactionManager`` class.  This is a
+  method that is generally meant to be used as a decorator for another
+  function::
+
+      from transaction import TransactionManager
+
+      tm = TransactionManager()
+      @tm.job(retries=3)
+      def ajob(t, persistentob, val=True):
+          ob.foo = val
+
+     ajob(apersistentob, val=1)
+
+  The decorated function may take any number of positional and keyword
+  arguments, but its signature *must* accept at least one positional
+  argument, which will be passed as a ``Transaction`` object by the
+  decorator.  Any remaining remaining arguments will be provided by the
+  caller.
+
+  A convenience decorator exists which uses the default
+  ThreadTransactionManager::
+
+      from transaction import job
+
+      @job(retries=3)
+      def ajob(t, persistentob, val=True):
+          ob.foo = val
+
+     ajob(apersistentob, val='aval')
+
+          
 1.2.0 (2011-12-05)
 ------------------
 

Modified: transaction/branches/chrism-job/transaction/_manager.py
===================================================================
--- transaction/branches/chrism-job/transaction/_manager.py	2012-04-04 07:59:18 UTC (rev 124929)
+++ transaction/branches/chrism-job/transaction/_manager.py	2012-04-04 08:18:26 UTC (rev 124930)
@@ -124,7 +124,7 @@
             return lambda f: self.job(f, retries)
 
         @functools.wraps(func)
-        def wrapper():
+        def wrapper(*arg, **kw):
             note = func.__doc__
             if note:
                 note = note.split('\n', 1)[0].strip()
@@ -139,7 +139,7 @@
                     t.note(note)
 
                 try:
-                    func(t)
+                    func(t, *arg, **kw)
                     t.commit()
                 except TransientError:
                     t.abort()

Modified: transaction/branches/chrism-job/transaction/tests/test_manager.py
===================================================================
--- transaction/branches/chrism-job/transaction/tests/test_manager.py	2012-04-04 07:59:18 UTC (rev 124929)
+++ transaction/branches/chrism-job/transaction/tests/test_manager.py	2012-04-04 08:18:26 UTC (rev 124930)
@@ -33,6 +33,19 @@
         self.assertEqual(self.txn.notes, ['func'])
         self.assertEqual(self.txn.committed, 1)
 
+    def test_job_with_args(self):
+        inst = self._makeOne()
+        inst.begin = self.begin
+        L = []
+        @inst.job
+        def func(tx, foo, bar=1):
+            L.append((foo, bar))
+        func('foo', bar=2)
+        self.assertEqual(L, [('foo', 2)])
+        self.assertEqual(self.begun, 1)
+        self.assertEqual(self.txn.notes, ['func'])
+        self.assertEqual(self.txn.committed, 1)
+        
     def test_job_no_retries_no_exception_func_has_doc(self):
         inst = self._makeOne()
         inst.begin = self.begin



More information about the checkins mailing list