Пример #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
    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
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)
    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
    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)