コード例 #1
0
class CommandTask(object):
    """
        Context Manager to handle both parallel running and maintenance mode, it:
          - do not allow to run two django command wir the same ``session_key``
          - do not allow to run the command if Maintenance-mode is active/pending

           session_key        id of current command
           force              if True ignore lock and run in parralel, if any
           timeout            timeout for locking release
           check_maintenance  check Maintenance mode
    """
    def __init__(self,
                 session_key,
                 force=False,
                 timeout=1,
                 check_maintenance=False):
        self._key = "%s.lock" % session_key
        self.lock = FileLock(self._key)

        if check_maintenance:
            if api.is_pending() or api.is_offline():
                raise MaintenanceModeError('Maintenance mode activated')

        if force:
            self.lock.break_lock()
        try:
            self.lock.acquire(timeout)
        except (AlreadyLocked, LockFailed, LockTimeout), e:
            raise CommandRunningError('Unable to lock', e)
コード例 #2
0
ファイル: utils.py プロジェクト: ppkt/django-site-maintenance
    def __init__(self,
                 session_key,
                 force=False,
                 timeout=1,
                 check_maintenance=False):
        """

        :param session_key: id of current command
        :param force: if True ignore lock and run in parallel, if any
        :param timeout: timeout for locking release
        :param check_maintenance: check Maintenance mode
        :return:
        """
        self._key = "%s.lock" % session_key
        self.lock = FileLock(self._key)

        if check_maintenance:
            if api.is_pending() or api.is_offline():
                raise MaintenanceModeError('Maintenance mode activated')

        if force:
            self.lock.break_lock()
        try:
            self.lock.acquire(timeout)
        except (AlreadyLocked, LockFailed, LockTimeout), e:
            raise CommandRunningError('Unable to lock', e)
コード例 #3
0
ファイル: utils.py プロジェクト: ppkt/django-site-maintenance
class CommandTask(object):
    """
    Context Manager to handle both parallel running and maintenance mode, it:
      - do not allow to run two django command with the same ``session_key``
      - do not allow to run the command if Maintenance-mode is active/pending
    """
    def __init__(self, session_key, force=False, timeout=1,
                 check_maintenance=False):
        """

        :param session_key: id of current command
        :param force: if True ignore lock and run in parallel, if any
        :param timeout: timeout for locking release
        :param check_maintenance: check Maintenance mode
        :return:
        """
        self._key = "%s.lock" % session_key
        self.lock = FileLock(self._key)

        if check_maintenance:
            if api.is_pending() or api.is_offline():
                raise MaintenanceModeError('Maintenance mode activated')

        if force:
            self.lock.break_lock()
        try:
            self.lock.acquire(timeout)
        except (AlreadyLocked, LockFailed, LockTimeout), e:
            raise CommandRunningError('Unable to lock', e)
コード例 #4
0
    def __init__(self,
                 session_key,
                 force=False,
                 timeout=1,
                 check_maintenance=False):
        self._key = "%s.lock" % session_key
        self.lock = FileLock(self._key)

        if check_maintenance:
            if api.is_pending() or api.is_offline():
                raise MaintenanceModeError('Maintenance mode activated')

        if force:
            self.lock.break_lock()
        try:
            self.lock.acquire(timeout)
        except (AlreadyLocked, LockFailed, LockTimeout), e:
            raise CommandRunningError('Unable to lock', e)
コード例 #5
0
    def  __init__( self, session_key, force=False, timeout=1, check_maintenance=False):
        self._key = "%s.lock" % session_key
        self.lock = FileLock(self._key)

        if check_maintenance:
            if api.is_pending() or api.is_offline():
                raise MaintenanceModeError('Maintenance mode activated')

        if force:
            self.lock.break_lock()
        try:
            self.lock.acquire(timeout)
        except (AlreadyLocked, LockFailed, LockTimeout), e:
            raise CommandRunningError('Unable to lock', e)
コード例 #6
0
ファイル: utils.py プロジェクト: ppkt/django-site-maintenance
    def __init__(self, session_key, force=False, timeout=1,
                 check_maintenance=False):
        """

        :param session_key: id of current command
        :param force: if True ignore lock and run in parallel, if any
        :param timeout: timeout for locking release
        :param check_maintenance: check Maintenance mode
        :return:
        """
        self._key = "%s.lock" % session_key
        self.lock = FileLock(self._key)

        if check_maintenance:
            if api.is_pending() or api.is_offline():
                raise MaintenanceModeError('Maintenance mode activated')

        if force:
            self.lock.break_lock()
        try:
            self.lock.acquire(timeout)
        except (AlreadyLocked, LockFailed, LockTimeout), e:
            raise CommandRunningError('Unable to lock', e)