code: def resume(connection: Connection, beaker: BeakerWrapper) -> None:
      logger.info("Checking if resumes are needed.")
  
      cursor = connection.cursor()
      cursor.execute("SELECT * FROM active_experiments")
      experiments = cursor.fetchall()
  
      for experiment_row in experiments:
          (
              experiment_id,
              original_id,
              max_resumes,
              current_resume,
          ) = experiment_row
          status = beaker.get_status(experiment_id)
          if status.is_end_state():
              stop_autoresume(connection, experiment_id)
              if status is BeakerStatus.preempted:
                  if current_resume >= max_resumes:
                      logger.info(
                          f"Experiment {experiment_id} preempted too many times "
                          f"({max_resumes}). Original experiment: {original_id}"
                      )
                  else:
                      new_experiment_id = beaker.resume(experiment_id)
                      logger.info(
                          f"Experiment {experiment_id} preempted "
                          f"({current_resume}/{max_resumes}). Resuming as: "
                          f"{new_experiment_id} Original experiment: {original_id}"
                      )
                      cursor.execute(
                          "INSERT INTO active_experiments VALUES (?, ?, ?, ?)",
                          (
                              new_experiment_id,
                              original_id,
                              max_resumes,
                              current_resume + 1,
                          ),
                      )
                      connection.commit()
              else:
                  logger.info(
                      f"Experiment {experiment_id} completed with status: "
                      f"{status}. Original experiment: {original_id}"
                  )
  
imports: import argparse
  import json
  import logging
  import os
  import random
  import sqlite3
  import subprocess
  import time
  from enum import Enum
  from logging.handlers import RotatingFileHandler
  from sqlite3 import Connection
  from subprocess import PIPE
label_desc: Use image node_id 4 for calling a global function with example usage: resume(connection, beaker) without return types