diff --git a/.travis.yml b/.travis.yml index 4179019..2b17e2a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,6 +4,7 @@ python: env: - DJANGO=1.6.1 DB=postgres install: + - python setup.py install - pip install -q Django==$DJANGO - pip install -r requirements.txt before_script: diff --git a/README.md b/README.md index f8aaa0f..8f8734f 100644 --- a/README.md +++ b/README.md @@ -12,34 +12,34 @@ If your application does not need a high performance mutex lock, Django DB Mutex ## How to Use Django DB Mutex The Django DB Mutex app provides a context manager and function decorator for locking a critical section of code. The context manager is used in the following way: - from db_mutex import db_mutex, DBMutexError, DBMutexTimeoutError + from db_mutex import db_mutex, DBMutexError, DBMutexTimeoutError - # Lock a critical section of code - try: - with db_mutex('lock_id'): - # Run critical code here - pass - except DBMutexError: - print 'Could not obtain lock' - except DBMutexTimeoutError: - print 'Task completed but the lock timed out' + # Lock a critical section of code + try: + with db_mutex('lock_id'): + # Run critical code here + pass + except DBMutexError: + print 'Could not obtain lock' + except DBMutexTimeoutError: + print 'Task completed but the lock timed out' You'll notice that two errors were caught from this context manager. The first one, DBMutexError, is thrown if the lock cannot be acquired. The second one, DBMutexTimeoutError, is thrown if the critical code completes but the lock timed out. More about lock timeout in the next section. The db_mutex decorator can also be used in a similar manner for locking a function. - from db_mutex import db_mutex, DBMutexError, DBMutexTimeoutError + from db_mutex import db_mutex, DBMutexError, DBMutexTimeoutError - @db_mutex('lock_id') - def critical_function(): - pass + @db_mutex('lock_id') + def critical_function(): + pass - try: - critical_function() - except DBMutexError: - print 'Could not obtain lock' - except DBMutexTimeoutError: - print 'Task completed but the lock timed out' + try: + critical_function() + except DBMutexError: + print 'Could not obtain lock' + except DBMutexTimeoutError: + print 'Task completed but the lock timed out' ## Lock Timeout Django DB Mutex comes with lock timeout baked in. This ensures that a lock cannot be held forever. This is especially important when working with segments of code that may run out of memory or produce errors that do not raise exceptions. diff --git a/db_mutex/VERSION b/db_mutex/VERSION index 49d5957..d917d3e 100644 --- a/db_mutex/VERSION +++ b/db_mutex/VERSION @@ -1 +1 @@ -0.1 +0.1.2 diff --git a/setup.py b/setup.py index f584e59..9169174 100644 --- a/setup.py +++ b/setup.py @@ -11,7 +11,8 @@ author='Wes Kendall', author_email='wesleykendall@gmail.com', packages=[ - 'manager_utils', + 'db_mutex', + 'db_mutex.migrations', ], classifiers=[ 'Programming Language :: Python',