Posts for the month of August 2009

Installing apache2 mod_fastcgi

Proper production configuration with Apache2 web server of a Nagare application involves using mod_fastcgi.

Here is a brief mod_fastcgi installation howto based on a Redhat system. This should easily be ported to any other nix plateform.

First of all, you'll need some basic development tools like gcc, gcc-c++, make , autoconf, automake ...

Then you should check you've required headers packages for Apache2 installed:

yum install httpd-devel libtools (for RHEL, centos, fedora based system)
up2date install httpd-devel libtools (for older RHEL systems)

OK, now let's install mod_fastcgi:

tar xzvf mod_fastcgi-2.4.6.tar.gz
cd mod_fastcgi-2.4.6
cp Makefile.AP2 Makefile
make top_dir=/usr/lib/httpd
make top_dir=/usr/lib/httpd install


SAVEPOINT transactions

The problem

In a function, you want to perform some operations on a database using sqlalchemy's session. If one of the operations fails, you want the session to go back to its state when the function was called.

The solution

Use a SAVEPOINT transaction:

from nagare import database
def my_func():
        with database.session.begin(nested=True):
            # let the job be done in a SAVEPOINT transaction
            # if an exception is raised in this block, session's state is restored
        return True
        return False