Skip to content

Latest commit

 

History

History
37 lines (24 loc) · 863 Bytes

decorators.rst

File metadata and controls

37 lines (24 loc) · 863 Bytes

Decorators

lockfile

Very useful for custom admin commands. If your command is scheduled every minute but might take longer than one minute, it would be good to prevent execution of the command if the preceeding execution is still running. Lockfiles come in handy here.

Note: This decorator requires the lockfile package to be installed. Either add it to your requirements if not already in or to get the latest version from pypi do:

pip install lockfile

You should create a setting LOCKFILE_PATH which points to /home/username/tmp/.

Usage:

from django_libs.decorators import lockfile
...

LOCKFILE = os.path.join(
    settings.LOCKFILE_PATH, 'command_name')

class Command(BaseCommand):

    @lockfile(LOCKFILE)
    def handle(self, *args, **kwargs):
        ...