Skip to main content

`bulk_update_or_create` for Django model managers

Project description

django-bulk-update-or-create

tests

Test coverage status

Current version on PyPi

monthly downloads

PyPI - Python Version

PyPI - Django Version

Distributed locks for Django using DB (MySQL/Postgres)

Given the limitation that Percona Cluster does not support MySQL locks, this app implements locks using select_for_update() (row locks).

Installation

pip install django-database-locks

Usage

from django.core.management.base import BaseCommand

from database_locks import locked

@locked
class Command(BaseCommand):
    ...
    def handle(self, *args, **options):
        self.stdout.write('Got the lock')

Docs

Both [lock]{.title-ref} and [locked]{.title-ref} have the same optional args:

:param lock_name: unique name in DB for this function
:param timeout: numbers of seconds to wait to acquire lock
:param lock_ttl: expiration timer of the lock, in seconds (set to None to infinite)
:param locked_by: owner id for the lock (if lock is active but owner is the same, returns acquired)
:param auto_renew: if set to True will re-acquire lock (for `lock_ttl` seconds) before `lock_ttl` is over.
                   auto_renew thread will raise KeyboardInterrupt on the main thread in case re-acquiring fails
:param retry: retry every `retry` seconds acquiring until successful. set to None or 0 to disable.
:param lost_lock_cb: callback function when lock is lost (when re-acquiring). defaults to raising LockException

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-bulk-update-or-create-0.1.1.tar.gz (2.9 kB view hashes)

Uploaded Source

Built Distribution

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page