code: def wait_for_file_ready(
      file_path: Path,
      poll_new_file_seconds: int,
      retries_loading_file: int,
  ):
      # This loop waits to make sure that the file is completely loaded on
      # disk before attempting to read. Docker sometimes will publish the
      # watchdog event before the file is actually fully on disk, causing
      # pikepdf to fail.
  
      tries = retries_loading_file + 1
      while tries:
          try:
              with pikepdf.Pdf.open(file_path) as pdf:
                  log.debug(f"{file_path} ready with {pdf.pages} pages")
                  return True
          except (FileNotFoundError, OSError) as e:
              log.info(f"File {file_path} is not ready yet")
              log.debug("Exception was", exc_info=e)
              time.sleep(poll_new_file_seconds)
              tries -= 1
          except pikepdf.PdfError as e:
              log.info(f"File {file_path} is not full written yet")
              log.debug("Exception was", exc_info=e)
              time.sleep(poll_new_file_seconds)
              tries -= 1
  
      return False
  
imports: import json
  import logging
  import shutil
  import sys
  import time
  from datetime import datetime
  from enum import Enum
  from pathlib import Path
  from typing import Annotated, Any
  import pikepdf
  import typer
  from dotenv import load_dotenv
  from watchdog.events import PatternMatchingEventHandler
  from watchdog.observers import Observer
  from watchdog.observers.polling import PollingObserver
  import ocrmypdf
label_desc: Use image node_id 2 for calling a global function with example usage: wait_for_file_ready(file_path, poll_new_file_seconds, retries_loading_file) and returns: False, True