Re: [Zope-dev] z3c.saconfig engine creation configuration

2009-06-25 Thread Malthe Borch

Laurence Rowe wrote:
I would rather we did not hardcode the defaults from SQLAlchemy into the 
engine directive (I guess they could change in future). Instead use a 
default of None and only supply the parameter if the config option is set.


Sounds right to me. Attached is an update patch.

\malthe
Index: src/z3c/saconfig/zcml.py
===
--- src/z3c/saconfig/zcml.py(revision 101264)
+++ src/z3c/saconfig/zcml.py(working copy)
@@ -27,13 +27,28 @@
 required=False,
 default=False)
 
+pool_size = zope.schema.Int(
+title=uPool size,
+description=uNumber of connections to keep open inside the connection 
pool.,
+required=False)
+
+pool_recycle = zope.schema.Int(
+title=uPool recycle,
+description=uRecycle connections after the given number of seconds 
have passed.,
+required=False)
+
+pool_timeout = zope.schema.Int(
+title=uPool timeout,
+description=uNumber of seconds to wait before giving up on getting a 
connection from the pool.,
+required=False)
+
 setup = zope.schema.BytesLine(
 title=u'After engine creation hook',
 description=u'Callback for creating mappers etc. One argument is 
passed, the engine',
 required=False,
 default=None)
+
 
-
 class ISessionDirective(zope.interface.Interface):
 Registers a database scoped session
 
@@ -62,16 +77,27 @@
 default=z3c.saconfig.utility.GloballyScopedSession)
 
 
-def engine(_context, url, name=u, echo=False, setup=None, twophase=False):
-factory = utility.EngineFactory(url, echo=echo)
-
+def engine(_context, url, name=u, echo=False, setup=None, twophase=False,
+   pool_size=None, pool_recycle=None, pool_timeout=None):
+# to avoid overriding defaults, we only provide pool configuration
+# parameters if set
+kwargs = {}
+if pool_size is not None:
+kwargs['pool_size'] = pool_size
+if pool_recycle is not None:
+kwargs['pool_recycle'] = pool_recycle
+if pool_timeout is not None:
+kwargs['pool_timeout'] = pool_timeout
+
+factory = utility.EngineFactory(url, echo=echo, **kwargs)
+
 zope.component.zcml.utility(
 _context,
 provides=interfaces.IEngineFactory,
 component=factory,
 permission=zope.component.zcml.PublicPermission,
 name=name)
-
+
 if setup:
 if _context.package is None:
 callback = resolve(setup)
___
Zope-Dev maillist  -  Zope-Dev@zope.org
http://mail.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope )


[Zope-dev] z3c.saconfig engine creation configuration

2009-06-24 Thread Malthe Borch
On MySQL, it's necessary to supply to ``pool_recycle`` parameter on 
engine creation, else the connection dies after some timeout and the 
pool is unable to hand out a session.


The result of this is that the first request fails whenever the 
connection has been dropped.


Attached is a patch that allows supplying these pool-related 
configuration options directly in the ZCML directive (db:engine).


\malthe
Index: src/z3c/saconfig/zcml.py
===
--- src/z3c/saconfig/zcml.py(revision 101264)
+++ src/z3c/saconfig/zcml.py(working copy)
@@ -27,13 +27,31 @@
 required=False,
 default=False)
 
+pool_size = zope.schema.Integer(
+title=uPool size,
+description=uNumber of connections to keep open inside the connection 
pool.,
+required=False,
+default=5)
+
+pool_recycle = zope.schema.Integer(
+title=uPool recycle,
+description=uRecycle connections after the given number of seconds 
have passed.,
+required=False,
+default=-1)
+
+pool_timeout = zope.schema.Integer(
+title=uPool timeout,
+description=uNumber of seconds to wait before giving up on getting a 
connection from the pool.,
+required=False,
+default=30)
+
 setup = zope.schema.BytesLine(
 title=u'After engine creation hook',
 description=u'Callback for creating mappers etc. One argument is 
passed, the engine',
 required=False,
 default=None)
+
 
-
 class ISessionDirective(zope.interface.Interface):
 Registers a database scoped session
 
@@ -62,8 +80,11 @@
 default=z3c.saconfig.utility.GloballyScopedSession)
 
 
-def engine(_context, url, name=u, echo=False, setup=None, twophase=False):
-factory = utility.EngineFactory(url, echo=echo)
+def engine(_context, url, name=u, echo=False, setup=None, twophase=False,
+   pool_size=5, pool_recycle=-1, pool_timeout=30):
+factory = utility.EngineFactory(
+url, echo=echo, pool_size=pool_size,
+pool_recycle=pool_recycle, pool_timeout=pool_timeout)
 
 zope.component.zcml.utility(
 _context,
___
Zope-Dev maillist  -  Zope-Dev@zope.org
http://mail.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope )


Re: [Zope-dev] z3c.saconfig engine creation configuration

2009-06-24 Thread Laurence Rowe
Malthe Borch wrote:
 On MySQL, it's necessary to supply to ``pool_recycle`` parameter on 
 engine creation, else the connection dies after some timeout and the 
 pool is unable to hand out a session.
 
 The result of this is that the first request fails whenever the 
 connection has been dropped.
 
 Attached is a patch that allows supplying these pool-related 
 configuration options directly in the ZCML directive (db:engine).
 
 \malthe

I would rather we did not hardcode the defaults from SQLAlchemy into the 
engine directive (I guess they could change in future). Instead use a 
default of None and only supply the parameter if the config option is set.

Laurence

___
Zope-Dev maillist  -  Zope-Dev@zope.org
http://mail.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope )