Code Monkey home page Code Monkey logo

django-db-locking's Introduction

Django-locking

https://coveralls.io/repos/github/vikingco/django-db-locking/badge.svg?branch=master https://travis-ci.org/vikingco/django-db-locking.svg?branch=master

Change note

This repository is forked from here. The model NonBlockingLock is changed to abstract = True.

Usage

The simplest use is by using it as a context manager:

with NonBlockingLock.objects.acquire_lock(obj=model_obj):
    model_obj.do_something()

Or you can keep track of the lock yourself:

try:
    lock = NonBlockingLock.objects.acquire_lock(obj=model_obj)
except AlreadyLocked:
    return False

model_obj.do_something()
lock.release()

If you have no Django model, or you want to be able to specify the lock name yourself, you can do that too:

# this will raise AlreadyLocked, if it's locked
lock = NonBlockingLock.objects.acquire_lock(lock_name='my_lock')
do_something()
lock.release()

Note that locks can expire automatically. There is a LOCK_MAX_AGE settings where you can specify a default lock release value for locks in your entire Django codebase. This value can be overridden per lock by setting the max_age parameter.

Test

You can run the tests with

tox

Releases

v2.0.0:
Merging of master and pre-django-1.8 branches Removes management command in favor of a celery task
v1.2.1:
Fix problem in migration to UUIDField for PostGres
v1.2.0:
Move id to UUIDField, add code quality checks and CI
v1.1.0:
Rename model to NonBlockingLock and add additional features
v1.0.1:
Corrected tests and code clean-up
v1.0.0:
Intial release.

django-db-locking's People

Contributors

chank1012 avatar fredvdvd avatar gvangool avatar kmahoney avatar kvsn avatar mrbox avatar nielsvanoch avatar sssaang avatar sunken37 avatar thenewguy avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.