code: def _wrap_with_lock(func, redis_params: RedisParams):
      if not redis_params.should_redis_lock:
          return func
  
      def wrapper(*args, **kwargs):
          redis_lock = _set_redis_lock(redis_params=redis_params)
          scheduler = _set_lock_scheduler(
              redis_lock=redis_lock, redis_params=redis_params
          )
  
          try:
              logger.debug(
                  f"Task lock of {redis_params.redis_key} locked."
              )
              result = func(*args, **kwargs)
              redis_lock.release()
              logger.debug(
                  f"Task lock of {redis_params.redis_key} released."
              )
              scheduler.shutdown()
              return result
          except BaseException as e:
              logger.debug(
                  f"Task lock of {redis_params.redis_key} released with BaseException."
              )
              redis_lock.release()
              scheduler.shutdown()
              raise e
  
      return wrapper
  
imports: import functools
  import os
  from logging import getLogger
  from typing import Callable, NamedTuple, Optional
  import redis
  from apscheduler.schedulers.background import BackgroundScheduler
label_desc: Use image node_id 4 for calling a global function with example usage: _wrap_with_lock(func, redis_params) and returns: wrapper, func, result