[CalendarServer-changes] [9662] CalendarServer/branches/users/glyph/q
source_changes at macosforge.org
source_changes at macosforge.org
Sat Aug 11 01:55:33 PDT 2012
Revision: 9662
http://trac.macosforge.org/projects/calendarserver/changeset/9662
Author: glyph at apple.com
Date: 2012-08-11 01:55:33 -0700 (Sat, 11 Aug 2012)
Log Message:
-----------
`__tbl__ ?\226?\134?\146 table; no need for double underscores / special naming when "table"
`is an SQL keyword anyway.
Modified Paths:
--------------
CalendarServer/branches/users/glyph/q/twext/enterprise/dal/record.py
CalendarServer/branches/users/glyph/q/twext/enterprise/queue.py
Property Changed:
----------------
CalendarServer/branches/users/glyph/q/
Modified: CalendarServer/branches/users/glyph/q/twext/enterprise/dal/record.py
===================================================================
--- CalendarServer/branches/users/glyph/q/twext/enterprise/dal/record.py 2012-08-11 08:55:32 UTC (rev 9661)
+++ CalendarServer/branches/users/glyph/q/twext/enterprise/dal/record.py 2012-08-11 08:55:33 UTC (rev 9662)
@@ -70,7 +70,7 @@
"Can't define a class from two or more tables at once."
)
table = base.table
- elif getattr(base, "__tbl__", None) is not None:
+ elif getattr(base, "table", None) is not None:
raise RuntimeError(
"Can't define a record class by inheriting one already "
"mapped to a table."
@@ -89,7 +89,7 @@
attrname = namer.namingConvention(column.model.name)
attrmap[attrname] = column
colmap[column] = attrname
- ns.update(__tbl__=table, __attrmap__=attrmap, __colmap__=colmap)
+ ns.update(table=table, __attrmap__=attrmap, __colmap__=colmap)
ns.update(attrmap)
return super(_RecordMeta, cls).__new__(cls, name, tuple(newbases), ns)
@@ -115,9 +115,9 @@
Superclass for all database-backed record classes. (i.e. an object mapped
from a database record).
- @cvar __tbl__: the table that represents this L{Record} in the
+ @cvar table: the table that represents this L{Record} in the
database.
- @type __tbl__: L{TableSyntax}
+ @type table: L{TableSyntax}
@cvar __colmap__: map of L{ColumnSyntax} objects to attribute names.
@type __colmap__: L{dict}
@@ -157,7 +157,7 @@
@classmethod
def _primaryKeyExpression(cls):
- return Tuple([ColumnSyntax(c) for c in cls.__tbl__.model.primaryKey])
+ return Tuple([ColumnSyntax(c) for c in cls.table.model.primaryKey])
def _primaryKeyValue(self):
@@ -209,7 +209,7 @@
@return: a L{Deferred} which fires when the underlying row has been
deleted.
"""
- return Delete(From=self.__tbl__,
+ return Delete(From=self.table,
Where=self._primaryKeyComparison(self._primaryKeyValue())
).on(self.__txn__)
@@ -243,7 +243,7 @@
"""
return cls._rowsFromQuery(
txn, Delete(Where=cls._primaryKeyComparison(primaryKey),
- From=cls.__tbl__, Return=list(cls.__tbl__)),
+ From=cls.table, Return=list(cls.table)),
lambda : NoSuchRecord()
).addCallback(lambda x: x[0])
@@ -268,8 +268,8 @@
kw = {}
if order is not None:
kw.update(OrderBy=order, Ascending=ascending)
- return cls._rowsFromQuery(txn, Select(list(cls.__tbl__),
- From=cls.__tbl__,
+ return cls._rowsFromQuery(txn, Select(list(cls.table),
+ From=cls.table,
Where=expr, **kw), None)
@@ -283,7 +283,7 @@
@param qry: a L{_DMLStatement} (XXX: maybe _DMLStatement or some
interface that defines 'on' should be public?) whose results are
- the list of columns in C{self.__tbl__}.
+ the list of columns in C{self.table}.
@param rozrc: The C{raiseOnZeroRowCount} argument.
@@ -294,7 +294,7 @@
selves = []
for row in rows:
self = cls()
- for (column, value) in zip(list(cls.__tbl__), row):
+ for (column, value) in zip(list(cls.table), row):
name = cls.__colmap__[column]
setattr(self, name, value)
self.__txn__ = txn
Modified: CalendarServer/branches/users/glyph/q/twext/enterprise/queue.py
===================================================================
--- CalendarServer/branches/users/glyph/q/twext/enterprise/queue.py 2012-08-11 08:55:32 UTC (rev 9661)
+++ CalendarServer/branches/users/glyph/q/twext/enterprise/queue.py 2012-08-11 08:55:33 UTC (rev 9662)
@@ -1,4 +1,4 @@
-# -*- test-case-name: twext.enterprise.test.test_adbapi2 -*-
+# -*- test-case-name: twext.enterprise.test.test_queue -*-
##
# Copyright (c) 2012 Apple Inc. All rights reserved.
#
@@ -21,6 +21,10 @@
want to defer and parallelize work that involves storing the results of
computation.
+By enqueuing with L{twisted.enterprise.queue}, you may guarantee that the work
+will I{eventually} be done, and reliably commit to doing it in the future, but
+defer it if it does not need to be done I{now}.
+
To pick a hypothetical example, let's say that you have a store which wants to
issue a promotional coupon based on a customer loyalty program, in response to
an administrator clicking on a button. Determining the list of customers to
@@ -71,8 +75,6 @@
From=schema.CUSTOMER).on(txn)):
# peerPool is a PeerConnectionPool
peerPool.enqueueWork(txn, CouponWork, customerID=customerID)
-
-
"""
from socket import getfqdn
@@ -234,7 +236,7 @@
@rtype: L{type}
"""
for subcls in cls.__subclasses__():
- if table == getattr(subcls, "__tbl__", None):
+ if table == getattr(subcls, "table", None):
return subcls
raise KeyError("No mapped {0} class for {1}.".format(
cls, table
@@ -643,7 +645,7 @@
self._whenCommitted.callback(None)
@passthru(self.pool.choosePeer().addCallback)
def peerChosen(peer):
- @passthru(peer.performWork(workItem.__tbl__,
+ @passthru(peer.performWork(workItem.table,
workItem.workID))
def performed(result):
self._whenExecuted.callback(None)
@@ -778,6 +780,8 @@
self.workerPool = WorkerConnectionPool()
self.peers = []
self.schema = schema
+ self._lastSeenTotalNodes = 1
+ self._lastSeenNodeIndex = 1
def addPeerConnection(self, peer):
@@ -862,7 +866,7 @@
@rtype: L{int}
"""
# TODO
- return 20
+ return self._lastSeenTotalNodes
def nodeIndex(self):
@@ -877,7 +881,7 @@
@rtype: L{int}
"""
# TODO
- return 6
+ return self._lastSeenNodeIndex
@inlineCallbacks
@@ -895,7 +899,7 @@
txn, itemType.created > self.queueProcessTimeout
)):
peer = yield self.choosePeer()
- yield peer.performWork(overdueItem.__tbl__,
+ yield peer.performWork(overdueItem.table,
overdueItem.workID)
finally:
yield txn.commit()
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20120811/00e4f1a9/attachment-0001.html>
More information about the calendarserver-changes
mailing list