Exemple #1
0
def _release_lock(lock_manager: ConsulLockManager, configuration: CliUnlockConfiguration):
    """
    Unlocks a lock.
    :param lock_manager: the lock manager
    :param configuration: the configuration required to unlock the lock
    """
    if configuration.regex_key_enabled:
        release_information = sorted(list(lock_manager.release_regex(key_regex=configuration.key)))
    else:
        release_information = lock_manager.release(key=configuration.key)
    print(json.dumps(release_information))

    exit(SUCCESS_EXIT_CODE)
def main(lock_key: str):
    lock_manager = ConsulLockManager()
    lock = lock_manager.find(lock_key)
    logger.debug(f"Lock with key \"{lock_key}\": {lock}")

    if lock is not None and lock.metadata is not None and JOB_ID_LOCK_METADATA_KEY in lock.metadata:
        job_id = lock.metadata[JOB_ID_LOCK_METADATA_KEY]
        logger.info(f"Lock currently held by CI job with ID: {job_id}")

        job_running = is_ci_job_running(job_id)
        logger.info(f"CI job with ID {job_id} {'is' if job_running else 'is not'} running")
        if not job_running:
            logger.info(f"Releasing lock for {lock.key} held by non-running job {job_id}")
            released = lock_manager.release(lock.key)
            logger.info("Released lock!" if released is not None else "Did not manage to release lock (someone else "
                                                                      "probably else released it before me)")
Exemple #3
0
def main(lock_key: str):
    lock_manager = ConsulLockManager()
    lock = lock_manager.find(lock_key)
    logger.debug(f"Lock with key \"{lock_key}\": {lock}")

    if lock is not None and lock.metadata is not None and JOB_ID_LOCK_METADATA_KEY in lock.metadata:
        job_id = lock.metadata[JOB_ID_LOCK_METADATA_KEY]
        logger.info(f"Lock currently held by CI job with ID: {job_id}")

        job_running = is_ci_job_running(job_id)
        logger.info(
            f"CI job with ID {job_id} {'is' if job_running else 'is not'} running"
        )
        if not job_running:
            logger.info(
                f"Releasing lock for {lock.key} held by non-running job {job_id}"
            )
            released = lock_manager.release(lock.key)
            logger.info("Released lock!" if released is not None else
                        "Did not manage to release lock (someone else "
                        "probably else released it before me)")
 def test_can_get_configuration_from_environment(self):
     with ConsulServiceController().start_service() as service:
         set_consul_env(service)
         lock_manager = ConsulLockManager()
         self.assertIsNone(lock_manager.release(KEY_1))
Exemple #5
0
 def test_can_get_configuration_from_environment(self):
     with ConsulServiceController().start_service() as service:
         set_consul_env(service)
         lock_manager = ConsulLockManager()
         self.assertIsNone(lock_manager.release(KEY_1))