durusmail: quixote-users: zodb and scgi design question
zodb and scgi design question
2004-05-22
2004-05-24
2004-05-25
zodb and scgi design question
Graham Fawcett
2004-05-25
Titus Brown wrote:

>Another approach would be to subclass the quixote.publish.Publisher
>to have it store a database handle; then you can create the handle
>at each SCGI server initialization, and access it by asking the
>publisher object for it.
>
>
>
A nice benefit of this approach is that you can choose to put your
get_transaction() commands in the Publisher code, rather than in your
app code: calling .commit() at the end of a successful request and
.abort() if you are handling a request error. I use something like this:

class TransactingPublisher(SessionPublisher):

    def try_publish (self, request, path):
        self.get_context().conn.sync()      # this is a ZEO thing...
        get_transaction().begin()
        return SessionPublisher.try_publish(self, request, path)

    def finish_successful_request (self, request):
        get_transaction().commit()
        return SessionPublisher.finish_successful_request(self, request)

    def finish_interrupted_request (self, request, exc):
        get_transaction().abort()
        return SessionPublisher.finish_interrupted_request(self,
request, exc)

    def finish_failed_request (self, request):
        get_transaction().abort()
        return SessionPublisher.finish_failed_request(self, request)

-- Graham



reply